Java 类org.openqa.selenium.support.FindBys 实例源码

项目:menggeqa    文件:DefaultElementByBuilder.java   
@Override protected By buildDefaultBy() {
    AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
    By defaultBy = null;
    FindBy findBy = annotatedElement.getAnnotation(FindBy.class);
    if (findBy != null) {
        defaultBy = super.buildByFromFindBy(findBy);
    }

    if (defaultBy == null) {
        FindBys findBys = annotatedElement.getAnnotation(FindBys.class);
        if (findBys != null) {
            defaultBy = super.buildByFromFindBys(findBys);
        }
    }

    if (defaultBy == null) {
        FindAll findAll = annotatedElement.getAnnotation(FindAll.class);
        if (findAll != null) {
            defaultBy = super.buildBysFromFindByOneOf(findAll);
        }
    }
    return defaultBy;
}
项目:qaf    文件:ElementFactory.java   
@SuppressWarnings("unchecked")
private boolean isDecoratable(Field field) {
    if (!hasAnnotation(field, com.qmetry.qaf.automation.ui.annotations.FindBy.class, FindBy.class,
            FindBys.class)) {
        return false;
    }
    if (WebElement.class.isAssignableFrom(field.getType())) {
        return true;
    }
    if (!(List.class.isAssignableFrom(field.getType()))) {
        return false;
    }
    Type genericType = field.getGenericType();
    if (!(genericType instanceof ParameterizedType)) {
        return false;
    }
    Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];

    return WebElement.class.isAssignableFrom((Class<?>) listType);
}
项目:selenide-appium    文件:SelenideAppiumFieldDecorator.java   
private boolean isDecoratableList(Field field, Class<?> type) {
  if (!List.class.isAssignableFrom(field.getType())) {
    return false;
  }

  Class<?> listType = getListGenericType(field);

  return listType != null && type.isAssignableFrom(listType)
    && (field.getAnnotation(FindBy.class) != null || field.getAnnotation(FindBys.class) != null);
}
项目:menggeqa    文件:DefaultElementByBuilder.java   
@Override protected void assertValidAnnotations() {
    AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();
    AndroidFindBy androidBy = annotatedElement.getAnnotation(AndroidFindBy.class);
    AndroidFindBys androidBys = annotatedElement.getAnnotation(AndroidFindBys.class);
    checkDisallowedAnnotationPairs(androidBy, androidBys);
    AndroidFindAll androidFindAll = annotatedElement.getAnnotation(AndroidFindAll.class);
    checkDisallowedAnnotationPairs(androidBy, androidFindAll);
    checkDisallowedAnnotationPairs(androidBys, androidFindAll);

    SelendroidFindBy selendroidBy = annotatedElement.getAnnotation(SelendroidFindBy.class);
    SelendroidFindBys selendroidBys = annotatedElement.getAnnotation(SelendroidFindBys.class);
    checkDisallowedAnnotationPairs(selendroidBy, selendroidBys);
    SelendroidFindAll selendroidFindAll =
        annotatedElement.getAnnotation(SelendroidFindAll.class);
    checkDisallowedAnnotationPairs(selendroidBy, selendroidFindAll);
    checkDisallowedAnnotationPairs(selendroidBys, selendroidFindAll);

    iOSFindBy iOSBy = annotatedElement.getAnnotation(iOSFindBy.class);
    iOSFindBys iOSBys = annotatedElement.getAnnotation(iOSFindBys.class);
    checkDisallowedAnnotationPairs(iOSBy, iOSBys);
    iOSFindAll iOSFindAll = annotatedElement.getAnnotation(iOSFindAll.class);
    checkDisallowedAnnotationPairs(iOSBy, iOSFindAll);
    checkDisallowedAnnotationPairs(iOSBys, iOSFindAll);

    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);
}
项目:webtester-core    文件:DefaultPageObjectFactory.java   
private Identification getIdentificationForField(Field field) {
    IdentifyUsing identifyUsing = field.getAnnotation(IdentifyUsing.class);
    if (identifyUsing != null) {
        return Identifications.fromAnnotation(identifyUsing);
    }
    FindBy findBy = field.getAnnotation(FindBy.class);
    if (findBy != null) {
        return Identifications.fromAnnotation(findBy);
    }
    FindBys findBys = field.getAnnotation(FindBys.class);
    if (findBys != null) {
        return Identifications.fromAnnotation(findBys);
    }
    return null;
}
项目:qaf    文件:ElementFactory.java   
@SuppressWarnings("unchecked")
public void initFields(Object classObj) {
    Field[] flds = ClassUtil.getAllFields(classObj.getClass(), AbstractTestPage.class);
    for (Field field : flds) {
        try {
            field.setAccessible(true);
            if (isDecoratable(field)) {
                Object value = null;
                if (hasAnnotation(field, FindBy.class, FindBys.class)) {
                    Annotations annotations = new Annotations(field);
                    boolean cacheElement = annotations.isLookupCached();
                    By by = annotations.buildBy();
                    if (List.class.isAssignableFrom(field.getType())) {
                        value = initList(by, context);
                    } else {
                        if (context instanceof WebElement) {
                            value = new QAFExtendedWebElement((QAFExtendedWebElement) context, by);
                        } else {
                            value = new QAFExtendedWebElement((QAFExtendedWebDriver) context, by, cacheElement);
                        }
                        initMetadata(classObj, field, (QAFExtendedWebElement) value);

                    }
                } else {
                    com.qmetry.qaf.automation.ui.annotations.FindBy findBy = field
                            .getAnnotation(com.qmetry.qaf.automation.ui.annotations.FindBy.class);
                    if (List.class.isAssignableFrom(field.getType())) {
                        value = initList(field, findBy.locator(), context, classObj);
                    } else {
                        if (QAFWebComponent.class.isAssignableFrom(field.getType())) {
                            value = ComponentFactory.getObject(field.getType(), findBy.locator(), classObj,
                                    context);

                        } else {
                            value = new QAFExtendedWebElement(findBy.locator());

                            if (context instanceof QAFExtendedWebElement) {
                                ((QAFExtendedWebElement) value).parentElement = (QAFExtendedWebElement) context;
                            }
                        }
                        initMetadata(classObj, field, (QAFExtendedWebElement) value);
                    }
                }

                field.set(classObj, value);
            }
        } catch (Exception e) {
            logger.error(e);
        }
    }
}
项目:webtester-core    文件:DefaultPageObjectFactory.java   
private boolean shouldInitializeField(Field field) {
    return field.getAnnotation(IdentifyUsing.class) != null || field.getAnnotation(FindBy.class) != null
        || field.getAnnotation(FindBys.class) != null;
}
项目:webtester-core    文件:FindBysConverter.java   
public FindBysConverter(FindBys findBys) {
    this.findBys = findBys;
}
项目:wiselenium    文件:ElementDecoratorChainTemplate.java   
private boolean isDecoratableList(Field field) {
    if (!List.class.isAssignableFrom(field.getType())) return false;

    // Type erasure in Java isn't complete. Attempt to discover the generic type of the list.
    Type genericType = field.getGenericType();
    if (!(genericType instanceof ParameterizedType)) return false;

    Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];

    if (!this.shouldDecorate((Class<?>) listType)) return false;

    if (field.getAnnotation(FindBy.class) == null && field.getAnnotation(FindBys.class) == null)
        return false;

    return true;
}
项目:webtester-core    文件:Identifications.java   
/**
 * Creates an {@link Identification identification} from the given
 * {@link FindBys @FindBys} instance.
 *
 * @param findBys the annotation instance to use.
 * @return the created identification
 * @since 0.9.9
 */
public static Identification fromAnnotation(FindBys findBys) {
    return new Identification(new FindBysConverter(findBys).buildBy());
}