/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final HtmlElement doc = page.getDocumentElement(); final Scriptable scriptable = (Scriptable) page.getEnclosingWindow().getScriptObject(); page.executeJavaScriptFunctionIfPossible(function_, scriptable, new Object[0], doc); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final HtmlElement doc = page.getDocumentElement(); final Scriptable scriptable = (Scriptable) page.getEnclosingWindow().getScriptObject(); page.executeJavaScriptFunctionIfPossible(function_, scriptable, new Object[0], doc); }
/** {@inheritDoc} */ @Override protected void runJavaScript(final HtmlPage page) { final HtmlElement doc = page.getDocumentElement(); final Scriptable scriptable = (Scriptable) page.getEnclosingWindow().getScriptObject(); page.executeJavaScriptFunctionIfPossible(function_, scriptable, new Object[0], doc); }
private ScriptResult executeEventHandler(final Event event, final Object[] propHandlerArgs) { final Function handler = getEventHandler(event.jsxGet_type()); if (handler != null) { final DomNode node = jsNode_.getDomNodeOrDie(); event.setCurrentTarget(jsNode_); final HtmlPage page = (HtmlPage) node.getPage(); LOG.debug("Executing " + event.jsxGet_type() + " handler for " + node); return page.executeJavaScriptFunctionIfPossible(handler, jsNode_, propHandlerArgs, node); } return null; }
private ScriptResult executeEventHandler(final Event event, final Object[] propHandlerArgs) { final Function handler = getEventHandler(event.jsxGet_type()); if (handler != null) { final DomNode node = jsNode_.getDomNodeOrDie(); event.setCurrentTarget(jsNode_); final HtmlPage page = (HtmlPage) node.getPage(); LOG.debug("Executing " + event.jsxGet_type() + " handler for " + node); return page.executeJavaScriptFunctionIfPossible(handler, jsNode_, propHandlerArgs, node); } return null; }
private ScriptResult executeEventHandler(final Event event, final Object[] propHandlerArgs) { final Function handler = getEventHandler(event.jsxGet_type()); if (handler != null) { final DomNode node = jsNode_.getDomNodeOrDie(); event.setCurrentTarget(jsNode_); final HtmlPage page = (HtmlPage) node.getPage(); LOG.debug("Executing " + event.jsxGet_type() + " handler for " + node); return page.executeJavaScriptFunctionIfPossible(handler, jsNode_, propHandlerArgs, node); } return null; }
@Override public String runTest(TestRun run) throws IOException { if (++runs == 50) { runs = 0; cleanUp(); init(); } try { page.set(webClient.get().<HtmlPage>getPage("about:blank")); } catch (IOException e) { throw new RuntimeException(e); } page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), "runtime.js"))); page.get().executeJavaScript(readFile(new File(run.getBaseDirectory(), "test.js"))); AsyncResult asyncResult = new AsyncResult(); Function function = (Function) page.get().executeJavaScript(readResource("teavm-htmlunit-adapter.js")) .getJavaScriptResult(); Object[] args = new Object[] { new NativeJavaObject(function, asyncResult, AsyncResult.class) }; page.get().executeJavaScriptFunctionIfPossible(function, function, args, page.get()); return (String) asyncResult.getResult(); }
/** * Injects an asynchronous script for execution and waits for its result. * * @param scriptBody The script body. * @param parameters The script parameters, which can be referenced using the {@code arguments} * JavaScript object. * @return The script result. */ public Object execute(String scriptBody, Object[] parameters) { AsyncScriptResult asyncResult = new AsyncScriptResult(); Function function = createInjectedScriptFunction(scriptBody, asyncResult); try { page.executeJavaScriptFunctionIfPossible(function, function, parameters, page.getDocumentElement()); } catch (ScriptException e) { throw new WebDriverException(e); } try { return asyncResult.waitForResult(); } catch (InterruptedException e) { throw new WebDriverException(e); } }
Function func = (Function) result.getJavaScriptResult(); result = page.executeJavaScriptFunctionIfPossible( func, (ScriptableObject) currentWindow.getScriptObject(),
private ScriptResult executeEventListeners(final boolean useCapture, final Event event, final Object[] args) { final boolean ie = jsNode_.getWindow().getWebWindow().getWebClient().getBrowserVersion().isIE(); ScriptResult allResult = null; final List<Function> handlers = getHandlers(event.jsxGet_type(), useCapture); if (handlers != null && !handlers.isEmpty()) { event.setCurrentTarget(jsNode_); final DomNode node = jsNode_.getDomNodeOrDie(); final HtmlPage page = (HtmlPage) node.getPage(); // make a copy of the list as execution of an handler may (de-)register handlers final List<Function> handlersToExecute = new ArrayList<Function>(handlers); for (final Function listener : handlersToExecute) { final ScriptResult result = page.executeJavaScriptFunctionIfPossible(listener, jsNode_, args, node); if (event.isPropagationStopped()) { allResult = result; } if (ie) { if (ScriptResult.isFalse(result)) { allResult = result; } else { final Object eventReturnValue = event.jsxGet_returnValue(); if (eventReturnValue instanceof Boolean && !((Boolean) eventReturnValue).booleanValue()) { allResult = new ScriptResult(false, page); } } } } } return allResult; }
private ScriptResult executeEventListeners(final boolean useCapture, final Event event, final Object[] args) { final boolean ie = jsNode_.getWindow().getWebWindow().getWebClient().getBrowserVersion().isIE(); ScriptResult allResult = null; final List<Function> handlers = getHandlers(event.jsxGet_type(), useCapture); if (handlers != null && !handlers.isEmpty()) { event.setCurrentTarget(jsNode_); final DomNode node = jsNode_.getDomNodeOrDie(); final HtmlPage page = (HtmlPage) node.getPage(); // make a copy of the list as execution of an handler may (de-)register handlers final List<Function> handlersToExecute = new ArrayList<Function>(handlers); for (final Function listener : handlersToExecute) { final ScriptResult result = page.executeJavaScriptFunctionIfPossible(listener, jsNode_, args, node); if (event.isPropagationStopped()) { allResult = result; } if (ie) { if (ScriptResult.isFalse(result)) { allResult = result; } else { final Object eventReturnValue = event.jsxGet_returnValue(); if (eventReturnValue instanceof Boolean && !((Boolean) eventReturnValue).booleanValue()) { allResult = new ScriptResult(false, page); } } } } } return allResult; }
private ScriptResult executeEventListeners(final boolean useCapture, final Event event, final Object[] args) { final boolean ie = jsNode_.getWindow().getWebWindow().getWebClient().getBrowserVersion().isIE(); ScriptResult allResult = null; final List<Function> handlers = getHandlers(event.jsxGet_type(), useCapture); if (handlers != null && !handlers.isEmpty()) { event.setCurrentTarget(jsNode_); final DomNode node = jsNode_.getDomNodeOrDie(); final HtmlPage page = (HtmlPage) node.getPage(); // make a copy of the list as execution of an handler may (de-)register handlers final List<Function> handlersToExecute = new ArrayList<Function>(handlers); for (final Function listener : handlersToExecute) { final ScriptResult result = page.executeJavaScriptFunctionIfPossible(listener, jsNode_, args, node); if (event.isPropagationStopped()) { allResult = result; } if (ie) { if (ScriptResult.isFalse(result)) { allResult = result; } else { final Object eventReturnValue = event.jsxGet_returnValue(); if (eventReturnValue instanceof Boolean && !((Boolean) eventReturnValue).booleanValue()) { allResult = new ScriptResult(false, page); } } } } } return allResult; }
@Override public Object executeScript(String script, final Object... args) { HtmlPage page = getPageToInjectScriptInto(); script = "function() {" + script + "\n};"; ScriptResult result = page.executeJavaScript(script); Function func = (Function) result.getJavaScriptResult(); Object[] parameters = convertScriptArgs(page, args); try { result = page.executeJavaScriptFunctionIfPossible( func, (ScriptableObject) getCurrentWindow().getScriptObject(), parameters, page.getDocumentElement()); } catch (Throwable ex) { throw new WebDriverException(ex); } return parseNativeJavascriptResult(result); }