Example usage for org.openqa.selenium.support.pagefactory Annotations buildBy

List of usage examples for org.openqa.selenium.support.pagefactory Annotations buildBy

Introduction

In this page you can find the example usage for org.openqa.selenium.support.pagefactory Annotations buildBy.

Prototype

@Override
public By buildBy() 

Source Link

Document

Looks for one of org.openqa.selenium.support.FindBy , org.openqa.selenium.support.FindBys or org.openqa.selenium.support.FindAll field annotations.

Usage

From source file:com.arcbees.test.ElementLocator.java

License:Apache License

private void processFindBy(Field field, Annotations annotations) {
    FindByDebugId findByDebugId = field.getAnnotation(FindByDebugId.class);
    if (findByDebugId != null) {
        String id = findByDebugId.value();
        by = new ByDebugId(id);
    } else {/*from   w w w  . j  a v a  2s .c  om*/
        by = annotations.buildBy();
    }
}

From source file:com.gwtplatform.carstore.cucumber.util.CarStoreElementLocator.java

License:Apache License

private void processFindBy(Field field, Annotations annotations) {
    FindByDebugId findByDebugId = field.getAnnotation(FindByDebugId.class);
    if (findByDebugId != null) {
        by = By.id(UIObject.DEBUG_ID_PREFIX + findByDebugId.value());
    } else {//  ww  w.j  a  v a 2s . c o  m
        by = annotations.buildBy();
    }
}

From source file:com.oracle.pgbu.common.pagefactory.DefaultElementLocator.java

License:Apache License

/**
 * Creates a new element locator.// ww  w  . j  a  va 2s  .  c  o  m
 * 
 * @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 DefaultElementLocator(SearchContext searchContext, Field field) {
    this.searchContext = searchContext;
    Annotations annotations = new Annotations(field);
    shouldCache = annotations.isLookupCached();
    by = annotations.buildBy();
}

From source file:com.qmetry.qaf.automation.ui.webdriver.ElementFactory.java

License:Open Source License

@SuppressWarnings("unchecked")
public void initFields(Object classObj) {
    Field[] flds = ClassUtil.getAllFields(classObj.getClass(), AbstractTestPage.class);
    for (Field field : flds) {
        try {//from w  w w .  ja  v a2  s  . co m
            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);
        }
    }
}

From source file:ui.auto.core.pagecomponent.ComponentFieldDecorator.java

License:Apache License

@Override
public Object decorate(ClassLoader loader, final Field field) {
    String dataValue = null;//from w ww .  ja  v  a2 s.  c o m
    String initialValue = null;
    String expectedValue = null;

    if (PageComponent.class.isAssignableFrom(field.getType())) {
        ElementLocator locator = factory.createLocator(field);
        if (locator == null)
            return null;

        ComponentData componentData = null;
        try {
            field.setAccessible(true);
            componentData = (ComponentData) field.get(page);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        if (componentData != null) {
            dataValue = componentData.getData(DataTypes.Data, false);
            initialValue = componentData.getData(DataTypes.Initial, false);
            expectedValue = componentData.getData(DataTypes.Expected, false);
        }

        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(field.getType());
        enhancer.setCallback(new ComponentMethodInterceptor(locator));
        Object componentProxy = enhancer.create();
        ((ComponentData) componentProxy).initializeData(dataValue, initialValue, expectedValue);
        Annotations annotations = new Annotations(field);
        ((PageComponent) componentProxy).selector = annotations.buildBy();
        return componentProxy;
    }

    return super.decorate(loader, field);
}

From source file:webdriver.elements.factory.UIElementLocator.java

License:Apache License

/**
 * Creates a new element locator.// w  w  w. jav a 2 s  .c om
 * 
 * @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 UIElementLocator(SearchContext searchContext, Field field) {
    this.searchContext = searchContext;
    Annotations annotations = new Annotations(field);
    shouldCache = annotations.isLookupCached();
    by = annotations.buildBy();
    //    ui = annotations.buildBy();
}