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

项目: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;
}
项目:SeleniumCucumber    文件:PageBase.java   
private By getFindByAnno(FindBy anno){
    log.info(anno);
    switch (anno.how()) {

    case CLASS_NAME:
        return new By.ByClassName(anno.using());
    case CSS:
        return new By.ByCssSelector(anno.using());
    case ID:
        return new By.ById(anno.using());
    case LINK_TEXT:
        return new By.ByLinkText(anno.using());
    case NAME:
        return new By.ByName(anno.using());
    case PARTIAL_LINK_TEXT:
        return new By.ByPartialLinkText(anno.using());
    case XPATH:
        return new By.ByXPath(anno.using());
    default :
        throw new IllegalArgumentException("Locator not Found : " + anno.how() + " : " + anno.using());
    }
}
项目: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);
}
项目:JDI    文件:WebAnnotationsUtil.java   
public static By findByToBy(FindBy locator) {
    if (locator == null) return null;
    if (!locator.id().isEmpty())
        return By.id(locator.id());
    if (!locator.className().isEmpty())
        return By.className(locator.className());
    if (!locator.xpath().isEmpty())
        return By.xpath(locator.xpath());
    if (!locator.css().isEmpty())
        return By.cssSelector(locator.css());
    if (!locator.linkText().isEmpty())
        return By.linkText(locator.linkText());
    if (!locator.name().isEmpty())
        return By.name(locator.name());
    if (!locator.partialLinkText().isEmpty())
        return By.partialLinkText(locator.partialLinkText());
    if (!locator.tagName().isEmpty())
        return By.tagName(locator.tagName());
    return null;
}
项目:JDI    文件:AppiumAnnotationsUtil.java   
public static By findByToBy(FindBy locator) {
    if (locator == null) return null;
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    if (!"".equals(locator.css()))
        return By.cssSelector(locator.css());
    if (!"".equals(locator.linkText()))
        return By.linkText(locator.linkText());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.partialLinkText()))
        return By.partialLinkText(locator.partialLinkText());
    if (!"".equals(locator.tagName()))
        return By.tagName(locator.tagName());
    return null;
}
项目:gga-selenium-framework    文件:AnnotationsUtil.java   
public static By getFindByLocator(FindBy locator) {
    if (locator == null) return null;
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    if (!"".equals(locator.css()))
        return By.cssSelector(locator.css());
    if (!"".equals(locator.linkText()))
        return By.linkText(locator.linkText());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.partialLinkText()))
        return By.partialLinkText(locator.partialLinkText());
    if (!"".equals(locator.tagName()))
        return By.tagName(locator.tagName());
    return null;
}
项目:gga-selenium-framework    文件:BaseElement.java   
private static By getNewLocator(Field field) {
    try {
        By byLocator = null;
        String locatorGroup = applicationVersion;
        if (locatorGroup != null) {
            JFindBy jFindBy = field.getAnnotation(JFindBy.class);
            if (jFindBy != null && locatorGroup.equals(jFindBy.group()))
                byLocator = getFindByLocator(jFindBy);
        }
        return (byLocator != null)
                ? byLocator
                : getFindByLocator(field.getAnnotation(FindBy.class));
    } catch (Exception | AssertionError ex) {
        throw exception(format("Error in get locator for type '%s'", field.getType().getName()) +
                LineBreak + ex.getMessage());
    }
}
项目:gga-selenium-framework    文件:CascadeInit.java   
private static By getNewLocator(Field field) {
    try {
        By byLocator = null;
        String locatorGroup = APP_VERSION;
        if (locatorGroup != null) {
            JFindBy jFindBy = field.getAnnotation(JFindBy.class);
            if (jFindBy != null && locatorGroup.equals(jFindBy.group()))
                byLocator = WebAnnotationsUtil.getFindByLocator(jFindBy);
        }
        return (byLocator != null)
                ? byLocator
                : WebAnnotationsUtil.getFindByLocator(field.getAnnotation(FindBy.class));
    } catch (Exception ex) {
        throw exception("Error in get locator for type '%s'", field.getType().getName() +
                LINE_BREAK + ex.getMessage());
    }
}
项目:gga-selenium-framework    文件:WebAnnotationsUtil.java   
public static By getFindByLocator(FindBy locator) {
    if (locator == null) return null;
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    if (!"".equals(locator.css()))
        return By.cssSelector(locator.css());
    if (!"".equals(locator.linkText()))
        return By.linkText(locator.linkText());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.partialLinkText()))
        return By.partialLinkText(locator.partialLinkText());
    if (!"".equals(locator.tagName()))
        return By.tagName(locator.tagName());
    return null;
}
项目:gga-selenium-framework    文件:CascadeInit.java   
private static By getNewLocator(Field field) {
    try {
        By byLocator = null;
        String locatorGroup = APP_VERSION;
        if (locatorGroup != null) {
            JFindBy jFindBy = field.getAnnotation(JFindBy.class);
            if (jFindBy != null && locatorGroup.equals(jFindBy.group()))
                byLocator = WebAnnotationsUtil.getFindByLocator(jFindBy);
        }
        return (byLocator != null)
                ? byLocator
                : WebAnnotationsUtil.getFindByLocator(field.getAnnotation(FindBy.class));
    } catch (Exception ex) {
        throw exception("Error in get locator for type '%s'", field.getType().getName() +
                LINE_BREAK + ex.getMessage());
    }
}
项目:gga-selenium-framework    文件:WebAnnotationsUtil.java   
public static By getFindByLocator(FindBy locator) {
    if (locator == null) return null;
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    if (!"".equals(locator.css()))
        return By.cssSelector(locator.css());
    if (!"".equals(locator.linkText()))
        return By.linkText(locator.linkText());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.partialLinkText()))
        return By.partialLinkText(locator.partialLinkText());
    if (!"".equals(locator.tagName()))
        return By.tagName(locator.tagName());
    return null;
}
项目:carina    文件:ExtendedElementLocator.java   
/**
 * Creates a new element locator.
 * 
 * @param searchContext
 *            The context to use when finding the element
 * @param field
 *            The field on the Page Object that will hold the located value
 */
public ExtendedElementLocator(SearchContext searchContext, Field field)
{
    this.searchContext = searchContext;

    if (field.isAnnotationPresent(FindBy.class))
    {
        LocalizedAnnotations annotations = new LocalizedAnnotations(field);
        this.shouldCache = annotations.isLookupCached();
        this.by = annotations.buildBy();
    }
    // Elements to be recognized by Alice
    if (field.isAnnotationPresent(FindByAI.class))
    {
        this.aiCaption = field.getAnnotation(FindByAI.class).caption();
        this.aiLabel = field.getAnnotation(FindByAI.class).label();
    }

    this.isPredicate = false;
    if (field.isAnnotationPresent(Predicate.class))
    {
        this.isPredicate = field.getAnnotation(Predicate.class).enabled();
    }
}
项目: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);
}
项目:bobcat    文件:ConditionsExplorer.java   
private void processLoadableContextForClass(Class clazz, ConditionHierarchyNode parent,
    Object injectee) {
  List<Field> declaredFields = Arrays.asList(clazz.getDeclaredFields());
  List<Field> applicableFields = declaredFields.stream()
      .filter(f -> (f.isAnnotationPresent(Inject.class))
          || (f.isAnnotationPresent(FindBy.class) && !f.getType().equals(WebElement.class)))
      .filter(f -> f.getType().isAnnotationPresent(PageObject.class))
      .collect(Collectors.toList());

  applicableFields.forEach(field -> {
    field.setAccessible(true);
    Object subjectInstance = null;
    try {
      subjectInstance = field.get(injectee);
    } catch (IllegalArgumentException | IllegalAccessException ex) {
      LOG.error(ex.getMessage(), ex);
    }
    ConditionHierarchyNode node = addChild(parent, new ClassFieldContext(subjectInstance,
        LoadableComponentsUtil.getConditionsFormField(field)));

    String className = node.getLoadableFieldContext().getSubjectClass().getCanonicalName();
    if (node.equals(findFirstOccurrence(node))) {
      LOG.debug("Building loadable components hierarchy tree for {}", className);
      processLoadableContextForClass(field.getType(), node, subjectInstance);
    } else {
      LOG.debug("Loadable components hierarchy tree for {} has already been built, skipping.",
          className);
    }
  });
}
项目: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);
}
项目:SeleniumCucumber    文件:PageBase.java   
protected By getElemetLocator(Object obj,String element) throws SecurityException,NoSuchFieldException {
    Class childClass = obj.getClass();
    By locator = null;
    try {
        locator = getFindByAnno(childClass.
                 getDeclaredField(element).
                 getAnnotation(FindBy.class));
    } catch (SecurityException | NoSuchFieldException e) {
        log.equals(e);
        throw e;
    }
    log.debug(locator);
    return locator;
}
项目:JDI    文件:WinCascadeInit.java   
private By findByToBy(FindBy locator) {
    if (locator == null)
        return null;
    if (!"".equals(locator.className()))
        return By.className(locator.className());
    if (!"".equals(locator.name()))
        return By.name(locator.name());
    if (!"".equals(locator.id()))
        return By.id(locator.id());
    if (!"".equals(locator.xpath()))
        return By.xpath(locator.xpath());
    return null;
}
项目:JDI    文件:AppiumCascadeInit.java   
protected By getNewLocatorFromField(Field field) {
    By byLocator = null;
    if (group == null)
        return findByToBy(field.getAnnotation(FindBy.class));
    JFindBy jFindBy = field.getAnnotation(JFindBy.class);
    if (jFindBy != null && group.equals(jFindBy.group()))
        byLocator = AppiumAnnotationsUtil.getFindByLocator(jFindBy);
    return byLocator != null
            ? byLocator
            : findByToBy(field.getAnnotation(FindBy.class));
}
项目:JDI    文件:TreeDropdown.java   
@Override
public void setup(Field field) {
    if (!fieldHasAnnotation(field, JTree.class, IDropDown.class))
        return;
    JTree jTree = field.getAnnotation(JTree.class);
    By selectLocator = findByToBy(jTree.select());
    avatar = new GetElementModule(selectLocator, this);
    //element = new GetElementType(selectLocator, this);
    //expander = new GetElementType(selectLocator, this);
    treeLocators = new ArrayList<>();
    for (FindBy fBy : jTree.levels())
        treeLocators.add(findByToBy(fBy));
}
项目: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;
}
项目:cinnamon    文件:WebDriverModule.java   
@Override
public void configure() {
    final FindByKeyInjectionListener findByKeyInjectionListener = new FindByKeyInjectionListener();
    bind(FindByKeyInjectionListener.class).toInstance(findByKeyInjectionListener);

    bindListener(Matchers.any(), new TypeListener() {
        @Override
        public <I> void hear(TypeLiteral<I> type, TypeEncounter<I> encounter) {
            if (hasFindByKeyAnnotation(type.getRawType())) {
                encounter.register(findByKeyInjectionListener);
            }
        }

        private boolean hasFindByKeyAnnotation(Class<?> clazz) {
            while (clazz != null) {
                for (Field field : clazz.getDeclaredFields()) {
                    if (field.isAnnotationPresent(FindByKey.class) || field.isAnnotationPresent(FindBy.class) || field
                            .isAnnotationPresent(FindAll.class)) {
                        return true;
                    }
                }
                // If this Class represents either the Object class, an interface, a primitive type, or void, then
                // null is returned.
                clazz = clazz.getSuperclass();
            }
            return false;
        }
    });
}
项目:cinnamon    文件:Annotations.java   
public By buildBy() {
    By ans = null;

    FindAll findAll = field.getAnnotation(FindAll.class);
    if (findAll != null) {
        ans = buildBysFromFindByOneOf(findAll);
    }

    FindBy findBy = field.getAnnotation(FindBy.class);
    if (ans == null && findBy != null) {
        ans = buildByFromFindBy(findBy);
    }

    FindByKey findByKey = field.getAnnotation(FindByKey.class);
    if (ans == null && findByKey != null) {
        ans = buildByFromFindByKey(findByKey);
    }

    if (ans == null) {
        ans = buildByFromDefault();
    }

    if (ans == null) {
        throw new IllegalArgumentException("Cannot determine how to locate element " + field);
    }

    return ans;
}
项目:senbot    文件:ElementService.java   
public FindBy getFindByDescriptor(String viewName, String elementName) {
    Class pageRepresentationReference = getReferenceService().getPageRepresentationReference(viewName);
    Field field = getElementFieldFromReferencedView(pageRepresentationReference, viewName, elementName);

    FindBy findByAnnotatio = field.getAnnotation(FindBy.class);
    return findByAnnotatio;
}
项目:carina    文件:ExtendedFieldDecorator.java   
protected ExtendedWebElement proxyForLocator(ClassLoader loader, Field field, ElementLocator locator)
{
    InvocationHandler handler = new LocatingElementHandler(locator);
    WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[]
    { WebElement.class, WrapsElement.class, Locatable.class }, handler);
    return new ExtendedWebElement(proxy, field.getName(), field.isAnnotationPresent(FindBy.class) ? new LocalizedAnnotations(field).buildBy() : null, webDriver);
}
项目:unidle-old    文件:GenericPage.java   
@PostConstruct
protected void initializeKnownElements() {

    final Builder<String, List<WebElement>> builder = ImmutableMap.builder();

    ReflectionUtils.doWithFields(getClass(),
                                 new FieldCallback() {
                                     @Override
                                     @SuppressWarnings("unchecked")
                                     public void doWith(final Field field) throws IllegalArgumentException, IllegalAccessException {
                                         final String name = lowerCase(join(splitByCharacterTypeCamelCase(field.getName()), ' '));

                                         field.setAccessible(true);
                                         final Object value = ReflectionUtils.getField(field, GenericPage.this);

                                         if (value instanceof List) {
                                             builder.put(name, (List<WebElement>) value);
                                         }
                                         else if (value instanceof WebElement) {
                                             builder.put(name, Collections.singletonList((WebElement) value));
                                         }
                                     }
                                 },
                                 new AnnotationFieldFilter(FindBy.class));

    knownElements = builder.build();
}
项目: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);
        }
    }
}
项目:JDI    文件:WebAnnotationsUtil.java   
public static void fillLocator(FindBy value, Consumer<By> action) {
    By by = findByToBy(value);
    if (by != null)
        action.accept(by);
}
项目:JDI    文件:WebCascadeInit.java   
protected By getNewLocatorFromField(Field field) {
    JFindBy[] jfindbys = field.getAnnotationsByType(JFindBy.class);
    if (jfindbys.length > 1) {
        JFindBy groupFindBy = single(jfindbys, j -> group.equals(j.group()));
        if (groupFindBy != null)
            return findByToBy(groupFindBy);
        groupFindBy = single(jfindbys, j -> j.group().equals(""));
        if (groupFindBy != null)
            return findByToBy(groupFindBy);
    }
    if (field.isAnnotationPresent(JFindBy.class)) {
        return findByToBy(field.getAnnotation(JFindBy.class));
    }
    if (field.isAnnotationPresent(FindBy.class)) {
        return findByToBy(field.getAnnotation(FindBy.class));
    }
    if (field.isAnnotationPresent(Css.class)) {
        return findByToBy(field.getAnnotation(Css.class));
    }
    if (field.isAnnotationPresent(XPath.class)) {
        return findByToBy(field.getAnnotation(XPath.class));
    }
    if (field.isAnnotationPresent(ByText.class)) {
        return findByToBy(field.getAnnotation(ByText.class));
    }
    if (field.isAnnotationPresent(Attribute.class)) {
        return findByToBy(field.getAnnotation(Attribute.class));
    }
    if (field.isAnnotationPresent(ByClass.class)) {
        return findByToBy(field.getAnnotation(ByClass.class));
    }
    if (field.isAnnotationPresent(ById.class)) {
        return findByToBy(field.getAnnotation(ById.class));
    }
    if (field.isAnnotationPresent(ByName.class)) {
        return findByToBy(field.getAnnotation(ByName.class));
    }
    if (field.isAnnotationPresent(NgRepeat.class)) {
        return findByToBy(field.getAnnotation(NgRepeat.class));
    }
    if (field.isAnnotationPresent(NgBinding.class)) {
        return findByToBy(field.getAnnotation(NgBinding.class));
    }
    if (field.isAnnotationPresent(NgModel.class)) {
        return findByToBy(field.getAnnotation(NgModel.class));
    }
    if (field.isAnnotationPresent(ByTitle.class)) {
        return findByToBy(field.getAnnotation(ByTitle.class));
    }
    if (field.isAnnotationPresent(ByTag.class)) {
        return findByToBy(field.getAnnotation(ByTag.class));
    }
    if (field.isAnnotationPresent(ByType.class)) {
        return findByToBy(field.getAnnotation(ByType.class));
    }
    if (field.isAnnotationPresent(ByValue.class)) {
        return findByToBy(field.getAnnotation(ByValue.class));
    }
    return null;
}
项目:JDI    文件:WinCascadeInit.java   
@Override
protected By getNewLocatorFromField(Field field) {
    return findByToBy(field.getAnnotation(FindBy.class));
}
项目:JDI    文件:AppiumAnnotationsUtil.java   
public static void fillLocator(FindBy value, Consumer<By> action) {
    By by = findByToBy(value);
    if (by != null)
        action.accept(by);
}
项目: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    文件:FindByConverter.java   
public FindByConverter(FindBy findBy) {
    this.findBy = findBy;
}
项目:grafaces    文件:GrafacesContext.java   
public void initializePageFragment(Object childObject, WebElement childRoot, Object parentObject) {
    if (!hasPropertyFor(Root.class, childObject)) {
        fail("No property annotated with @Root in class " + childObject.getClass());
    }
    setInstanceOf(Root.class, childObject, childRoot);

    if (hasPropertyFor(Drone.class, childObject)) {
        WebDriver driver = getInstanceOf(Drone.class, parentObject, WebDriver.class);
        // FIXME when driver == null
                /*
                if (grapheneContext == null) {
            grapheneContext = GrapheneContext.getContextFor(ReflectionHelper.getQualifier(field.getAnnotations()));
        }
        grapheneContext.getWebDriver(xx.class) where xx is the class type of the field where annotation was placed on
       */
        setInstanceOf(Drone.class, childObject, driver);
    }


    try {
        List<Field> fields = ReflectionHelper.getFieldsWithAnnotation(childObject.getClass(), FindBy.class);
        for (Field field : fields) {
            By by = FindByUtilities.getCorrectBy(field, How.ID_OR_NAME);
            // WebElement
            if (field.getType().isAssignableFrom(WebElement.class)) {

                WebElement element = childRoot.findElement(by);
                ReflectionUtil.setValue(field, childObject, element);
                // List<WebElement>
            } else if (field.getType().isAssignableFrom(List.class) && getListType(field)
                    .isAssignableFrom(WebElement.class)) {
                List<WebElement> elements = childRoot.findElements(by);
                ReflectionUtil.setValue(field, childObject, elements);
            }

        }
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

    if (hasPropertyFor(Grafaces.class, childObject)) {
        setInstanceOf(Grafaces.class, childObject, this);
    }

    executeMethodsOfType(PostConstruct.class, childObject);
}
项目:senbot    文件:ElementService.java   
public String getElementLocatorFromReferencedView(String viewName, String elementName) {
    FindBy findByAnnotatio = getFindByDescriptor(viewName, elementName);
    return findByAnnotatio.how() + ":" + findByAnnotatio.using();
}
项目: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;
}
项目:carina    文件:ExtendedFieldDecorator.java   
public Object decorate(ClassLoader loader, Field field)
{
    if ((!field.isAnnotationPresent(FindBy.class) && !field.isAnnotationPresent(FindByAI.class)) /*Enable field decorator logic only in case of presence the FindBy/FindByAI annotation in the field*/ ||
            !(ExtendedWebElement.class.isAssignableFrom(field.getType()) || AbstractUIObject.class.isAssignableFrom(field.getType()) || isDecoratableList(field)) /*also verify that it is ExtendedWebElement or derived from AbstractUIObject or DecoratableList*/)
    {
        // returning null is ok in this method.
        return null;
    }

    ElementLocator locator;
    try
    {
        locator = factory.createLocator(field);
    } catch (Exception e)
    {
        LOGGER.error(e.getMessage(), e);
        return null;
    }
    if (locator == null)
    {
        return null;
    }

    if (ExtendedWebElement.class.isAssignableFrom(field.getType()))
    {
        return proxyForLocator(loader, field, locator);
    }
    if (AbstractUIObject.class.isAssignableFrom(field.getType()))
    {
        return proxyForAbstractUIObject(loader, field, locator);
    }
    else if (List.class.isAssignableFrom(field.getType()))
    {
        Type listType = getListType(field);
        if (ExtendedWebElement.class.isAssignableFrom((Class<?>) listType))
        {
            return proxyForListLocator(loader, field, locator);
        }
        else if (AbstractUIObject.class.isAssignableFrom((Class<?>) listType))
        {
            return proxyForListUIObjects(loader, field, locator);
        }
        else
        {
            return null;
        }
    } else
    {
        return null;
    }
}
项目:webtester-core    文件:Identifications.java   
/**
 * Creates an {@link Identification identification} from the given
 * {@link FindBy @FindBy} instance.
 *
 * @param findBy the annotation instance to use.
 * @return the created identification
 * @since 0.9.9
 */
public static Identification fromAnnotation(FindBy findBy) {
    return new Identification(new FindByConverter(findBy).buildBy());
}