Java 类org.openqa.selenium.support.pagefactory.Annotations 实例源码

项目:selenide-appium    文件:SelenideAppiumFieldDecorator.java   
@Override
public Object decorate(ClassLoader loader, Field field) {
  By selector = new Annotations(field).buildBy();
  if (selector instanceof ByIdOrName) {
    // throw new IllegalArgumentException("Please define locator for " + field);
    return decorateWithAppium(loader, field);
  } else if (WebElement.class.isAssignableFrom(field.getType())) {
    return ElementFinder.wrap(searchContext, selector, 0);
  } else if (ElementsCollection.class.isAssignableFrom(field.getType())) {
    return new ElementsCollection(new BySelectorCollection(searchContext, selector));
  } else if (ElementsContainer.class.isAssignableFrom(field.getType())) {
    return createElementsContainer(selector, field);
  } else if (isDecoratableList(field, ElementsContainer.class)) {
    return createElementsContainerList(field);
  } else if (isDecoratableList(field, SelenideElement.class)) {
    return SelenideElementListProxy.wrap(factory.createLocator(field));
  }

  return decorateWithAppium(loader, field);
}
项目: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);
        }
    }
}