AbstractJavaScriptEngine<?> javaScriptEngine = getJavaScriptEngine(); if (javaScriptEngine instanceof JavaScriptEngine) { ((JavaScriptEngine) javaScriptEngine).getContextFactory()
/** * Starts an interactive JavaScript debugger, and break at the next JavaScript execution. * * <p> * This is useful during debugging a test so that you can step execute and inspect state of JavaScript. * This will launch a Swing GUI, and the method returns immediately. * * <p> * Note that installing a debugger appears to make an execution of JavaScript substantially slower. * * <p> * TODO: because each script block evaluation in HtmlUnit is done in a separate Rhino context, * if you step over from one script block, the debugger fails to kick in on the beginning of the next script * block. * This makes it difficult to set a break point on arbitrary script block in the HTML page. We need to fix this * by tweaking {@link org.mozilla.javascript.tools.debugger.Dim.StackFrame#onLineChange(Context, int)}. */ public Dim interactiveJavaScriptDebugger() { Global global = new Global(); HtmlUnitContextFactory cf = ((JavaScriptEngine)getJavaScriptEngine()).getContextFactory(); global.init(cf); Dim dim = org.mozilla.javascript.tools.debugger.Main.mainEmbedded(cf, global, "Rhino debugger: " + testDescription.getDisplayName()); // break on exceptions. this catch most of the errors dim.setBreakOnExceptions(true); return dim; } }