Page Objects pattern is very well described here.
Graphene comes with support for this pattern. The main additions are:
- Better support for initialization of the Page Objects. Graphene automatically enrich the Page Object's injection points (e.g. @FindBy).
- Page Objects can contain Page Fragments and they are also properly initialized.
- Page Objects can contain any injection point which Arquillian supports - e.g. @Drone WebDriver for injecting browser instance
- Page Objects can encapsulate their location
You have already saw the default way of initializing Page Objects in the parent Page Abstractions page. Let's showcase Graphene way of doing this!
- Implement a Page Object.
- Declare it in the test.
- Annotate it with org.jboss.arquillian.graphene.spi.annotations.Page annotation.
- And that's all! No need to initialize Page Object via any factory method.
To see it in action, consider please code snippets below, which demonstrates testing of a simple web page with progress bar and two buttons.
|Page Objects can be declared also as nested classes. However, to better decouple test logic from the structure of the tested page, it is recommended to declare Page Objects as standalone classes.|
|Your are not limited just with injecting WebElement instances. You can in the same way inject your Page Fragments, or even java.util.List of Page Fragments/WebElements.|
|Note that you have to use private fields for all Graphene initialized WebElement/Page Fragments etc. Use their getters from tests.|
|Page Objects in Multiple Browsers scenario|
If you use page abstractions together with parallel browsers feature, be sure to check Using Page Abstractions with Multiple Browsers.
The deployment according to which the @Location value will be resolved, and the browser into which the page will be loaded can be determined in the following way: