public class VaniJavaScriptExecutor extends Object implements org.openqa.selenium.JavascriptExecutor
JavascriptExecutor. It prepares
the source, which is sent to the browser. This means that all dependencies,
js-interface's sources and plugins are concatenated if it's necessary.JavaScriptCallFunction,
JsCallFunction,
JavaScript,
JavaScriptFunction| Modifier and Type | Field and Description |
|---|---|
protected static String |
BOUND_CALL |
protected static String |
CALL |
protected org.openqa.selenium.JavascriptExecutor |
jsExecutor |
protected JavaScriptSource<?> |
jsSource |
protected org.apache.commons.logging.Log |
logger |
| Constructor and Description |
|---|
VaniJavaScriptExecutor(org.openqa.selenium.JavascriptExecutor jsExecutor,
JavaScriptSource<?> jsSource) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
appendSource(StringBuilder builder,
JavaScriptSource<?> jsSource,
Set<JavaScriptSource<?>> processingSources)
This method resolves the source code for specified
JavaScriptSource and set it to provided StringBuilder.The
builder will contains following things at the end in this order:
dependencies, which are not already available (see
DetectionScript) or already appended to the builder. |
protected Object |
doExecute(String script,
Object... args)
This method is only wrapper for
JavascriptExecutor.executeScript(String, Object...) and check
whether there was a js-error. |
protected Object |
doExecuteAsync(String script,
Object... args)
This method is only wrapper for
JavascriptExecutor.executeAsyncScript(String, Object...) and
check whether there was a js-error. |
Object |
execute(String methodName,
JavaScriptFunction jsFunctionAnnotation,
Object... args)
Executes JavaScript in the context of the currently selected frame or
window.
|
Object |
executeAsyncScript(String script,
Object... args) |
Object |
executeScript(String script,
Object... args) |
protected String |
getCallSource(String funcName)
This method builds the call source.
|
org.openqa.selenium.JavascriptExecutor |
getWrappedExecutor() |
protected Object |
handleResult(Object result)
This method checks whether the javascript execution returned an string
starting with js-error key.
|
protected boolean |
mustInject(JavaScriptSource<?> jsSource)
This method checks whether provided
JavaScriptSource declares a
detection script. |
protected String |
prepareSource(String source)
This method will prepare source code, which will be sent to browser.
|
protected static final String BOUND_CALL
protected static final String CALL
protected final org.apache.commons.logging.Log logger
protected org.openqa.selenium.JavascriptExecutor jsExecutor
protected JavaScriptSource<?> jsSource
public VaniJavaScriptExecutor(org.openqa.selenium.JavascriptExecutor jsExecutor,
JavaScriptSource<?> jsSource)
public Object executeScript(String script, Object... args)
executeScript in interface org.openqa.selenium.JavascriptExecutorpublic Object executeAsyncScript(String script, Object... args)
executeAsyncScript in interface org.openqa.selenium.JavascriptExecutorpublic Object execute(String methodName, JavaScriptFunction jsFunctionAnnotation, Object... args)
Within the script, use document to refer to the current
document. Note that local variables will not be available once the script
has finished executing, though global variables will persist.
If the script has a return value (i.e. if the script contains a
return statement), then the following steps will be taken:
Arguments must be a number, a boolean, a String, WebElement, or a List of any combination of the above. An exception will be thrown if the arguments do not meet these criteria. The arguments will be made available to the JavaScript via the "arguments" magic variable, as if the function were called via "Function.apply"
methodName - name of calling js-inteface methodjsFunctionAnnotation - annotation of calling js-interface methodargs - The arguments to the script. May be emptyVaniJavaScriptExecutor#CALL} for wrapping call sourceprotected String getCallSource(String funcName)
JsCallFunction), the function will be
called by apply-function.funcName - name of javascript functionVaniJavaScriptExecutor#BOUND_CALL} (default call source)protected Object doExecute(String script, Object... args)
JavascriptExecutor.executeScript(String, Object...) and check
whether there was a js-error.script - script code which should be executedargs - The arguments to the script. May be empty.JavaScriptException - will be thrown, when provided argument is a string starting
with js-error keyprotected Object doExecuteAsync(String script, Object... args) throws JavaScriptException
JavascriptExecutor.executeAsyncScript(String, Object...) and
check whether there was a js-error.script - script code which should be executedargs - The arguments to the script. May be empty.JavaScriptException - will be thrown, when provided argument is a string starting
with js-error keyprotected Object handleResult(Object result) throws JavaScriptException
JavaScriptException
will be thrown, which contains the returns script error.result - result of the javascript executionJavaScriptException - will be thrown, when provided argument is a string starting
with js-error keyprotected String prepareSource(String source) throws JavaScriptException
source - source of bound functionJavaScriptException - will be thrown if an error occurred during checking whether
script must be injected.VaniJavaScriptExecutor#appendSource(StringBuilder, JavaScriptSource, Set)}protected void appendSource(StringBuilder builder, JavaScriptSource<?> jsSource, Set<JavaScriptSource<?>> processingSources) throws JavaScriptException
JavaScriptSource and set it to provided StringBuilder.The
builder will contains following things at the end in this order:
DetectionScript) or already appended to the builder. If a
dependency also declares a dependency or plugin it will be handled in
same order.DetectionScript), it will be skipped.builder.
builder - jsSource - processingSources - JavaScriptException - will be thrown, when an error occurred during checking
whether script is already available.protected boolean mustInject(JavaScriptSource<?> jsSource)
JavaScriptSource declares a
detection script. If there is a detection script, it will be executed and
its return value will be inverted and returned.jsSource - public org.openqa.selenium.JavascriptExecutor getWrappedExecutor()
Copyright © 2016. All rights reserved.