@Target(value={TYPE,FIELD}) @Retention(value=RUNTIME) @Documented public @interface JavaScript
Interfaces or abstract classes annotated with this interface invokes a script on a page under test.
This annotation is used for both, annotating the type and marking the injection point as demonstrated in following example.
The interface can also automatically retrieve JavaScript file dependencies, using Dependency
annotation.
Default implementation of ExecutionResolver
which invokes the script on the page automatically converts all types
defined by JavascriptExecutor.executeScript(String, Object...)
and additionally it converts enumerations to their
string representation.
Default implementation also automatically resolves the getters and setters name as accessors to the object. Java method called setName can either call setName method on target JavaScript object or it can set a value of name property of that object. Similarly getName can either call a getName method or return name property.
The name of a method is automatically diverged from name of a Java interface method, however it can be re-defined using
MethodName
annotation.
window.helloworld = { hello: function() { return "Hello World!"; } }
@JavaScript("helloworld") @Dependency(sources = "helloworld.js") public interface HelloWorld { String hello(); }
public static class TestCase { @JavaScript private HelloWorld helloWorld; @Test public void testHelloWorld() { assertEquals("Hello World!", helloWorld.hello()); } }
Modifier and Type | Optional Element and Description |
---|---|
Class<? extends ExecutionResolver> |
executionResolver
Returns
ExecutionResolver which will execute the JavaScript interface. |
String |
implementation
Indicates that this interface is just an interface and its implementation (another JavaScript interface) is specified in
linked implementation class.
|
String |
value
The name of JavaScript interface - Graphene will look up the global object of that name on a page.
|
public abstract String value
The name of JavaScript interface - Graphene will look up the global object of that name on a page.
Defaults to window.<type> where type is name of the interface annotated with this annotation.
public abstract String implementation
public abstract Class<? extends ExecutionResolver> executionResolver
ExecutionResolver
which will execute the JavaScript interface.ExecutionResolver
which will invokes this interfaceCopyright © 2016 JBoss by Red Hat. All rights reserved.