Please explain the difference between @FindAll and @FindBys annotations in webdriver page factory concept.
Look at the JavaDocs:
Annotation Type FindBys
@Retention(value=RUNTIME)
@Target(value={FIELD,TYPE})
public @interface FindBys
Used to mark a field on a Page Object to indicate that lookup should use a series of @FindBy tags in a chain as described in ByChained Eg:
@FindBys({@FindBy(id = "foo"),
@FindBy(className = "bar")})
Annotation Type FindAll
@Retention(value=RUNTIME)
@Target(value={FIELD,TYPE})
public @interface FindAll
Used to mark a field on a Page Object to indicate that lookup should use a series of @FindBy tags It will then search for all elements that match any of the FindBy criteria. Note that elements are not guaranteed to be in document order. Eg:
@FindAll({@FindBy(how = How.ID, using = "foo"),
@FindBy(className = "bar")})
We can use these annotations in those cases when we have more than a single criteria to to identify one or more WebElement objects.
@FindBys : When the required WebElement objects need to match all of the given criteria use @FindBys annotation
@FindAll : When required WebElement objects need to match at least one of the given criteria use @FindAll annotation
Usage:
@FindBys( {
@FindBy(className = "class1")
@FindBy(className = "class2")
} )
private List<WebElement> elementsWithBoth_class1ANDclass2;
Here List elementsWithBothclass1ANDclass2 will contain any WebElement which satisfies both criteria.
@FindAll({
@FindBy(className = "class1")
@FindBy(className = "class2")
})
private List<WebElement> elementsWithEither_class1ORclass2
Here List elementsWithEither_class1ORclass2 will contain all those WebElement that satisfies any one of the criteria.
to put it in simple words, @FindBys have AND conditional relationship among the @FindBy whereas @FindAll has OR conditional relationship.
@FindAll
can contain multiple @FindBy
and will return all the elements which matches any @FindBy
in a single list.
Example:
@FindAll({
@FindBy(id = "one"),
@FindBy(id = "two")
})
public List<WebElement> allElementsInList;
Whereas,
@FindBys
will return the elements depending upon how @FindBy
specified inside it.
@FindBys({
@FindBy(id = "one"),
@FindBy(className = "two")
})
public List<WebElement> allElementsInList;
Where allElementsInList
contains all the elements having className="two"
inside id="one"