Search in sources :

Example 1 with FindBy

use of org.openqa.selenium.support.FindBy 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 FindBy

use of org.openqa.selenium.support.FindBy 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 FindBy

use of org.openqa.selenium.support.FindBy 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 FindBy

use of org.openqa.selenium.support.FindBy in project masquerade by cuba-platform.

the class Components method getTargetFieldValue.

protected static Object getTargetFieldValue(Class clazz, Field field, By parentBy) {
    String fieldName = field.getName();
    Wire wire = field.getAnnotation(Wire.class);
    Object fieldValue;
    if (wire != null) {
        if (field.getType() == SelenideElement.class) {
            fieldValue = $(parentBy);
        } else if (field.getType() == By.class) {
            fieldValue = parentBy;
        } else if (field.getType() == Logger.class) {
            fieldValue = LoggerFactory.getLogger(clazz);
        } else {
            String[] path = wire.path();
            if (path.length == 0) {
                path = new String[] { fieldName };
            }
            By fieldBy;
            if (parentBy == BODY_MARKER_BY) {
                fieldBy = byPath(path);
            } else {
                fieldBy = byChain(parentBy, byPath(path));
            }
            fieldValue = wireClassBy(field.getType(), fieldBy);
        }
    } else {
        FindBy findBy = field.getAnnotation(FindBy.class);
        if (findBy != null) {
            By selector = new Annotations(field).buildBy();
            By fieldBy;
            if (parentBy == BODY_MARKER_BY) {
                fieldBy = selector;
            } else {
                fieldBy = byChain(parentBy, selector);
            }
            fieldValue = wireClassBy(field.getType(), fieldBy);
        } else {
            fieldValue = null;
        }
    }
    return fieldValue;
}
Also used : Annotations(org.openqa.selenium.support.pagefactory.Annotations) By(org.openqa.selenium.By) FindBy(org.openqa.selenium.support.FindBy) FindBy(org.openqa.selenium.support.FindBy)

Example 5 with FindBy

use of org.openqa.selenium.support.FindBy 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

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