@Location("index.html") public class SomePage { // just some page object }
Page object encapsulates some page. This page has its location. We can see location of a page as some kind of metadata logically related to that page. In order to have this location information wired with page as such, there is @Location annotation by which you can specify where some page is located. Check out this simple example:
@Location("index.html") public class SomePage { // just some page object }
The above location value will be treated as the relative URL to the value of @ArquillianResource URL contextRoot - e.g. http://localhost:8080/app/index.html.
Use @Location("") to denote that page object's location equals to the context root of the deployed application.
By putting @Location annotation at page object, when you inject this page annotated with @InitialPage annotation into a test method, that page object will be open at that location as the very first action in a test method. Lets see an example:
@Test public void testMethod(@InitialPage SomePage page) { // here you will have your page already open, WebDriver opens index.html // other code }
Every location has some scheme. In the previous example, there is used HTTP scheme by default. There are multiple schemes as:
Treats location as http:// scheme. You do not have to specify scheme paramater since by default it is HTTP
@Location("http://www.google.com") // by default scheme = Scheme.HTTP.class when omitted @Location("https://www.google.com") // works with https as well, scheme is same
You can not do this
@Location("www.google.com")
since it is not possible to say if this location is relative (as index.html) or absolute. You have to use http:// scheme string explicitly to open regular www page on the net.
Treats location as file:// scheme
@Location(scheme = Scheme.FILE.class, value = "file:///full/path/to/page.html")
Treats location as resource:// scheme
@Location(scheme = Scheme.RESOURCE.class, value = "resource://...")
The "resource://" prefix denotes that the page is not deployed to any container, and will be loaded from local file-system. The same you can achieve with prefix "file".
Check out Graphene Utility Class documentation page, to see how you can use Graphene.goTo(Class<?> pageObjectClass) method to load Page Object location in the browser.
Custom scheme is implemented e.g. in Droidium so you can open your activities as pages. You have to extend org.jboss.arquillian.graphene.spi.location.Scheme and add your own scheme like this:
public DroidiumScheme extends Scheme { private static final String scheme = "and-activity://"; @Override public String toString() { return scheme; } }
Then you have to implement your own org.jboss.arquillian.graphene.location.decider.LocationDecider which is in Graphene SPI as well. This decider resolves scheme value which will WebDriver instance subsequently open via get() method.
Finally you have to register this decider as a service in Arquillian's loadable extension.
After that, you can do this:
@Location(scheme = DroidiumScheme.class, value = "this.is.my.android.activity") public class SomeActivityPage { }
@Test public void testMyActivity(@InitialPage SomeActivityPage myActivity) { // here your Android activity will be already open by WebDriver }
Imaging you are dealing only with Android activities so specifying scheme = DroidiumScheme.class is not needed. You can set default scheme in arquillian.xml like this:
<extension qualifier="graphene"> <!-- Droidium everywhere --> <property name="scheme">org.arquillian.droidium.native_.spi.location.DroidiumScheme</property> </extension>
Now you can use it like:
@Location("this.is.my.android.activity")