webdriver页面工厂中@FindAll和@FindBys注释之间的区别
请解释webdriver页面工厂概念中@FindAll和@FindBys注释之间的区别。
当我们有多个标准来识别一个或多个WebElement对象时,我们可以在这些情况下使用这些注释。
@FindBys:当所需的WebElement对象需要匹配所有给定的条件时,使用@FindBys注释
@FindAll:当需要WebElement对象需要匹配至少一个给定条件时,使用@FindAll注释
用法:
@FindBys( { @FindBy(className = "class1") @FindBy(className = "class2") } ) private List elementsWithBoth_class1ANDclass2;
这里List elementsWithBothclass1ANDclass2将包含满足两个条件的任何WebElement。
@FindAll({ @FindBy(className = "class1") @FindBy(className = "class2") }) private List elementsWithEither_class1ORclass2
这里List elementsWithEither_class1ORclass2将包含满足任何一个条件的所有WebElement。
@FindAll
可以包含多个@FindBy
,并将在单个列表中返回与任何@FindBy
匹配的所有元素。
例:
@FindAll({ @FindBy(id = "one"), @FindBy(id = "two") }) public List allElementsInList;
然而,
@FindBys
将根据@FindBy
在其中指定的方式返回元素。
@FindBys({ @FindBy(id = "one"), @FindBy(className = "two") }) public List allElementsInList;
其中allElementsInList
包含在id="one"
内具有className="two"
所有元素
看看JavaDocs :
注释类型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")})
注释类型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")})
换句话说,@ FindBys在@FindBy之间有AND条件关系,而@FindAll有OR条件关系。