Graphene comes with support for Selenium 2 @FindBy annotation, which can be used to locate your elements in your Page Objects, Page Fragments and in tests as well.
Basic usage
import org.openqa.selenium.support.FindBy;
public class TestClassOrPageObjectOrPageFragment {
@FindBy(id = "myButton")
private WebElement button;
@FindBy(className = "foo-bar")
private MyPageFragmentImpl myFragment;
@FindBy(css = ".blah-class")
private List<WebElement> myListOfWebElements;
@FindBy(css = ".foo-bar")
private List<MyPageFragmentImpl> myListOfPageFragments;
@FindBy(id = "select")
private Select select;
}
As you can see, the @FindBy annotation usage is pretty the same as with the Selenium 2.
Graphene allows you to annotate these fields:
No need to initialize those fields with any Page Factory. Graphene will do so for you automatically.
Graphene supports also the @FindBys annotation and the How usage.
Default locating strategy for locating elements with empty @FindBy
You can often find this pattern in your tests when locating elements with use of @FindBy:
@FindBy(id = "loginButton")
WebElement loginButton;
When using @FindBy annotation with Graphene, the following is equal to the above:
@FindBy
WebElement loginButton;
Graphene by default automatically infers the element by using ByIdOrName location strategy and the field name as the locator.
It can be configured with the defaultElementLocatingStrategy property in arquillian.xml. The possible values are the lowercase values of How enum.