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

下面列出了怎么用org.openqa.selenium.support.pagefactory.Annotations的API类实例代码及写法,或者点击链接到github查看源代码。

@Override
public Object decorate(ClassLoader loader, Field field) {
  builder.setAnnotated(field);
  By selector = builder.buildBy();

  if (selector == null) {
    selector = new Annotations(field).buildBy();
  }

  if (selector instanceof ByIdOrName) {
    return decorateWithAppium(loader, field);
  }
  else if (SelenideElement.class.isAssignableFrom(field.getType())) {
    return ElementFinder.wrap(driver, driver.getWebDriver(), selector, 0);
  }
  else if (ElementsCollection.class.isAssignableFrom(field.getType())) {
    return new ElementsCollection(new BySelectorCollection(driver, 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(driver, factory.createLocator(field));
  }

  return super.decorate(loader, field);
}
 
源代码2 项目: bobcat   文件: FieldAnnotationsProviderTest.java
@ParameterizedTest
@ValueSource(strings = {"findBy", "findBys", "findAll"})
void shouldReturnSeleniumAnnotationsWhenFieldIsDecoratedWithFindBys(String field)
    throws NoSuchFieldException {
  assertThat(FieldAnnotationsProvider.create(TestData.class.getDeclaredField(field), null))
      .isInstanceOf(Annotations.class);
}
 
源代码3 项目: 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 = $(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);
		}
	}
}
 
源代码4 项目: bobcat   文件: FieldAnnotationsProvider.java
/**
 * Provides an {@link AbstractAnnotations} implementation based on provided field's annotations.
 *
 * @param field    which annotations are checked
 * @param injector to provide Bobcat-augmented annotations
 * @return <ul>
 * <li>{@link Annotations} for fields decorated with {@link org.openqa.selenium.support.FindBy}, {@link org.openqa.selenium.support.FindAll} or {@link org.openqa.selenium.support.FindBys}</li>
 * <li>{@link BobcatAnnotations} for fields decorated with {@link com.cognifide.qa.bb.qualifier.FindPageObject}</li>
 * </ul>
 * @throws IllegalArgumentException when the field is not decorated with any of the above annotations
 */
public static AbstractAnnotations create(Field field, Injector injector) {
  if (AnnotationsHelper.isFindByAnnotationPresent(field)) {
    return new Annotations(field);
  }
  if (AnnotationsHelper.isFindPageObjectAnnotationPresent(field)) {
    return new BobcatAnnotations(field, injector);
  }
  throw new IllegalArgumentException(
      "Field is not marked by any supported annotation: " + field.toGenericString());
}
 
 类所在包
 类方法
 同包方法