org.openqa.selenium.support.pagefactory.Annotations Java Examples

The following examples show how to use org.openqa.selenium.support.pagefactory.Annotations. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SelenideAppiumFieldDecorator.java    From selenide-appium with MIT License 5 votes vote down vote up
@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);
}
 
Example #2
Source File: FieldAnnotationsProviderTest.java    From bobcat with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@ValueSource(strings = {"findBy", "findBys", "findAll"})
void shouldReturnSeleniumAnnotationsWhenFieldIsDecoratedWithFindBys(String field)
    throws NoSuchFieldException {
  assertThat(FieldAnnotationsProvider.create(TestData.class.getDeclaredField(field), null))
      .isInstanceOf(Annotations.class);
}
 
Example #3
Source File: ElementFactory.java    From qaf with MIT License 4 votes vote down vote up
@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);
		}
	}
}
 
Example #4
Source File: FieldAnnotationsProvider.java    From bobcat with Apache License 2.0 3 votes vote down vote up
/**
 * 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());
}