difference between @FindAll and @FindBys annotations in webdriver page factory

前端 未结 4 1417
日久生厌
日久生厌 2020-12-09 04:05

Please explain the difference between @FindAll and @FindBys annotations in webdriver page factory concept.

相关标签:
4条回答
  • 2020-12-09 04:44

    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")})
    
    0 讨论(0)
  • 2020-12-09 04:48

    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.

    0 讨论(0)
  • 2020-12-09 04:52

    to put it in simple words, @FindBys have AND conditional relationship among the @FindBy whereas @FindAll has OR conditional relationship.

    0 讨论(0)
  • 2020-12-09 04:53

    @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"

    0 讨论(0)
提交回复
热议问题