public abstract class PageObject extends WindowRelated
Superclass for page objects. Each class sub-classing it will be automatically injected by the injector in
session-scope - there is no need for Inject annotation.
During the dependency injection the injector automatically initializes all fields in a page object, when the
field has one Find annotation and it's type is one of the followings:
WebElement - the field will represent a single element on the page,WebElements - the field will represent multiple elements on the page.The fields even can be private. Examples:
@Find(selector="#ok-button") private WebElement okButton; @Find(selector=".main-table tr") private WebElements tableRows;
After the Find annotation some other (modifier) annotations can be added to a field.
With the Position annotation the desired element's relative position can be specified to an anchor element.
With the Relation annotation the structural relation between the desired and anchor elements can be
specified. Examples:
@Find(selector="button") @Position(type=PositionType.LEFT_FROM, selector="#ok-button") private WebElement cancelButton; @Find(selector="button") @Relation(type=RelationType.DESCENDANT_OF, selector="#modal-window") private WebElement modalButton;
When the content of a page is included by an iframe parent, then a single Find annotation will
not find the desired elements. In this case, a Frame annotation should be added to the page object class,
which specifies the search properties of the iframe element. Every element search inside of this page object
will be automatically performed inside of that iframe.
A page object encapsulates the technical functionality of a well-defined part of the application under test. For example, it can represent a single web-page, a navigation bar, a frame, ... Every necessary action available on that object is specified in the page object as public method. Every assertion that can be verified on that object is represented by a public method too.
The abstract PageObject class contains some useful protected methods. These are for:
doWith(WebElement) and tryWith(WebElement),browser(),expectations(),getConfigurationValue(String).Examples:
public void clickButton() {
// clicking a button
doWith(okButton).click();
}
private WebElement findButton() {
// finding a specific element on page
return browser().find("#ok-button");
}
public void openPage() {
// opening a specific URL
browser().openURL("http://localhost/page");
}
public void expectButtonIsVisible() {
// verifying that button is visible
expectations().expect(okButton).toBe().visible();
}
public void expectPageIsOpened() {
// verifying that a specific URL is opened
expectations().expect(browser()).toHave().url("http://localhost/page");
}
private Long getDefaultTimeout() {
// returning configuration value as number
return getConfigurationValue("ibello.timeout.default").toLong();
}
All public methods of a page object are considered as test steps and therefore automatically logged when called.
The log will contain the descriptive name of the methods. If the method has a Name annotation, then
the descriptive name will be the one specified by that annotation. Otherwise the descriptive name will be transformed
from the name of the method; all underscore character will be replaced by a space, and all camel-case substring
will be separated into multiple words. Method parameters are also included in the descriptive name. '$' signs in
method name are placeholders for parameters.
Examples:
public void clickBigButton() {
// descriptive name is "Click Big Button"
}
public void open_page() {
// descriptive name is "Open Page"
}
@Name("Close Modal Dialog")
public void doSomething() {
// descriptive name is "Close Modal Dialog"
}
@Name("Click Button in Row ${0}")
public void clickButton(int index) {
// the name may contain parameter substitution marker
// eg. clickButton(5) will have descriptive name: "Click Button in Row 5"
}
public void click_$_button(String title) {
// the '$' character will be replaced with the title
// eg. click_$_button("Open") will have descriptive name: "Click Open Button"
}
A page object should have a public default constructor.
Created by Kornél Simon, 2022