@Override public void runTest(TestRun run) throws IOException { if (++runs == 50) { runs = 0; cleanUp(); init(); } try { page.set(webClient.get().getPage("about:blank")); } catch (IOException e) { throw new RuntimeException(e); } HtmlPage pageRef = page.get(); pageRef.executeJavaScript(readFile(new File(run.getBaseDirectory(), run.getFileName()))); boolean decodeStack = Boolean.parseBoolean(System.getProperty(TeaVMTestRunner.JS_DECODE_STACK, "true")); File debugFile = decodeStack ? new File(run.getBaseDirectory(), run.getFileName() + ".teavmdbg") : null; RhinoResultParser resultParser = new RhinoResultParser(debugFile); AsyncResult asyncResult = new AsyncResult(); Function function = (Function) page.get().executeJavaScript(readResource("teavm-htmlunit-adapter.js")) .getJavaScriptResult(); Object[] args = new Object[] { decodeStack ? createStackDecoderFunction(resultParser) : null, new NativeJavaObject(function, asyncResult, AsyncResult.class) }; pageRef.executeJavaScriptFunction(function, function, args, page.get()); resultParser.parseResult((Scriptable) asyncResult.getResult(), run.getCallback()); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final DomElement doc = page.getDocumentElement(); final Scriptable scriptable = page.getEnclosingWindow().getScriptableObject(); page.executeJavaScriptFunction(function_, scriptable, args_, doc); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final DomElement doc = page.getDocumentElement(); final Scriptable scriptable = page.getEnclosingWindow().getScriptableObject(); page.executeJavaScriptFunction(function_, scriptable, args_, doc); }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * Execute a Function in the given context. * * @param function the JavaScript Function to call * @param thisObject the "this" object to be used during invocation * @param args the arguments to pass into the call * @param htmlElementScope the HTML element for which this script is being executed * This element will be the context during the JavaScript execution. If null, * the context will default to the page. * @return a ScriptResult which will contain both the current page (which may be different than * the previous page and a JavaScript result object. */ public ScriptResult executeJavaScriptFunction(final Object function, final Object thisObject, final Object[] args, final DomNode htmlElementScope) { if (!getWebClient().getOptions().isJavaScriptEnabled()) { return new ScriptResult(null); } return executeJavaScriptFunction((Function) function, (Scriptable) thisObject, args, htmlElementScope); }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * Execute a Function in the given context. * * @param function the JavaScript Function to call * @param thisObject the "this" object to be used during invocation * @param args the arguments to pass into the call * @param htmlElementScope the HTML element for which this script is being executed * This element will be the context during the JavaScript execution. If null, * the context will default to the page. * @return a ScriptResult which will contain both the current page (which may be different than * the previous page and a JavaScript result object. */ public ScriptResult executeJavaScriptFunction(final Object function, final Object thisObject, final Object[] args, final DomNode htmlElementScope) { if (!getWebClient().getOptions().isJavaScriptEnabled()) { return new ScriptResult(null); } return executeJavaScriptFunction((Function) function, (Scriptable) thisObject, args, htmlElementScope); }
page.executeJavaScriptFunction(function, thisObject, args, node);
page.executeJavaScriptFunction(function, thisObject, args, node);