Search in sources :

Example 1 with FindBys

use of org.openqa.selenium.support.FindBys in project selenium_java by sergueik.

the class DynamicAnnotations method buildBy.

public By buildBy() {
    assertValidAnnotations();
    By ans = null;
    FindBys findBys = field.getAnnotation(FindBys.class);
    if (findBys != null) {
        // building a chained locator
        ans = buildByFromFindBys(findBys);
    }
    FindAll findAll = field.getAnnotation(FindAll.class);
    if (ans == null && findAll != null) {
        // building a find by one of locator
        ans = buildBysFromFindByOneOf(findAll);
    }
    FindBy findBy = field.getAnnotation(FindBy.class);
    if (ans == null && findBy != null) {
        // building an ordinary locator
        ans = buildByFromFindBy(findBy);
    }
    if (ans == null) {
        // without locator annotation will build a locator based on field name
        // id or name
        ans = buildByFromDefault();
    }
    if (ans == null) {
        throw new IllegalArgumentException("Cannot determine how to locate element " + field);
    }
    return ans;
}
Also used : FindAll(org.openqa.selenium.support.FindAll) By(org.openqa.selenium.By) FindBy(org.openqa.selenium.support.FindBy) FindBys(org.openqa.selenium.support.FindBys) FindBy(org.openqa.selenium.support.FindBy)

Example 2 with FindBys

use of org.openqa.selenium.support.FindBys in project java-client by appium.

the class DefaultElementByBuilder method assertValidAnnotations.

@Override
protected void assertValidAnnotations() {
    AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
    FindBy findBy = annotatedElement.getAnnotation(FindBy.class);
    FindBys findBys = annotatedElement.getAnnotation(FindBys.class);
    checkDisallowedAnnotationPairs(findBy, findBys);
    FindAll findAll = annotatedElement.getAnnotation(FindAll.class);
    checkDisallowedAnnotationPairs(findBy, findAll);
    checkDisallowedAnnotationPairs(findBys, findAll);
}
Also used : FindAll(org.openqa.selenium.support.FindAll) AnnotatedElement(java.lang.reflect.AnnotatedElement) FindBy(org.openqa.selenium.support.FindBy) FindBys(org.openqa.selenium.support.FindBys)

Example 3 with FindBys

use of org.openqa.selenium.support.FindBys in project java-client by appium.

the class DefaultElementByBuilder method buildDefaultBy.

@Override
protected By buildDefaultBy() {
    AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
    By defaultBy = null;
    FindBy findBy = annotatedElement.getAnnotation(FindBy.class);
    if (findBy != null) {
        defaultBy = new FindBy.FindByBuilder().buildIt(findBy, (Field) annotatedElement);
    }
    if (defaultBy == null) {
        FindBys findBys = annotatedElement.getAnnotation(FindBys.class);
        if (findBys != null) {
            defaultBy = new FindBys.FindByBuilder().buildIt(findBys, (Field) annotatedElement);
        }
    }
    if (defaultBy == null) {
        FindAll findAll = annotatedElement.getAnnotation(FindAll.class);
        if (findAll != null) {
            defaultBy = new FindAll.FindByBuilder().buildIt(findAll, (Field) annotatedElement);
        }
    }
    return defaultBy;
}
Also used : Field(java.lang.reflect.Field) FindAll(org.openqa.selenium.support.FindAll) FindBy(org.openqa.selenium.support.FindBy) By(org.openqa.selenium.By) ContentMappedBy(io.appium.java_client.pagefactory.bys.ContentMappedBy) AnnotatedElement(java.lang.reflect.AnnotatedElement) FindBy(org.openqa.selenium.support.FindBy) FindBys(org.openqa.selenium.support.FindBys)

Example 4 with FindBys

use of org.openqa.selenium.support.FindBys in project selenium_java by sergueik.

the class DynamicAnnotations method assertValidAnnotations.

public void assertValidAnnotations() {
    FindBys findBys = field.getAnnotation(FindBys.class);
    FindAll findAll = field.getAnnotation(FindAll.class);
    FindBy findBy = field.getAnnotation(FindBy.class);
    if (findBys != null && findBy != null) {
        throw new IllegalArgumentException("If you use a '@FindBys' annotation, " + "you must not also use a '@FindBy' annotation");
    }
    if (findAll != null && findBy != null) {
        throw new IllegalArgumentException("If you use a '@FindAll' annotation, " + "you must not also use a '@FindBy' annotation");
    }
    if (findAll != null && findBys != null) {
        throw new IllegalArgumentException("If you use a '@FindAll' annotation, " + "you must not also use a '@FindBys' annotation");
    }
}
Also used : FindAll(org.openqa.selenium.support.FindAll) FindBys(org.openqa.selenium.support.FindBys) FindBy(org.openqa.selenium.support.FindBy)

Aggregations

FindAll (org.openqa.selenium.support.FindAll)4 FindBy (org.openqa.selenium.support.FindBy)4 FindBys (org.openqa.selenium.support.FindBys)4 AnnotatedElement (java.lang.reflect.AnnotatedElement)2 By (org.openqa.selenium.By)2 ContentMappedBy (io.appium.java_client.pagefactory.bys.ContentMappedBy)1 Field (java.lang.reflect.Field)1