Example usage for org.openqa.selenium.support.pagefactory DefaultElementLocatorFactory DefaultElementLocatorFactory

List of usage examples for org.openqa.selenium.support.pagefactory DefaultElementLocatorFactory DefaultElementLocatorFactory

Introduction

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

Prototype

public DefaultElementLocatorFactory(SearchContext searchContext) 

Source Link

Usage

From source file:com.cognifide.qa.bb.scope.ContextStack.java

License:Apache License

private PageObjectContext getDefaultPageObjectContext(WebDriver webDriver) {
    ElementLocatorFactory elementLocatorFactory = new DefaultElementLocatorFactory(webDriver);
    FramePath framePath = new FramePath();
    return new PageObjectContext(elementLocatorFactory, framePath);
}

From source file:com.cognifide.qa.bb.utils.PageObjectInjector.java

License:Apache License

/**
 * This method creates the object of type clazz within context defined by the top web element and the
 * frame path provided as the parameter.
 *
 * @param clazz     PageObject class./*from  www  .  j a va2s  .co m*/
 * @param framePath instance of FramePath.
 * @param <T>       type of PageObject class that will be returned.
 * @return instance of Injector.
 */
public <T> T inject(Class<T> clazz, FramePath framePath) {
    final ElementLocatorFactory elementLocatorFactory = new DefaultElementLocatorFactory(webDriver);
    stack.push(new PageObjectContext(elementLocatorFactory, framePath));
    try {
        return injector.getInstance(clazz);
    } finally {
        stack.pop();
    }
}

From source file:com.github.wiselenium.factory.WisePageFactory.java

License:Open Source License

private static FieldDecorator initDecorator(SearchContext searchContext, Field field) {
    FieldDecorator decorator;//w  w  w.j  av a 2 s .c  o  m
    AjaxElement ajaxElementAnnotation = field.getAnnotation(AjaxElement.class);
    if (ajaxElementAnnotation != null) {
        int timeout = ajaxElementAnnotation.timeOutInSeconds();
        decorator = new WiseDecorator(new AjaxElementLocatorFactory(searchContext, timeout));
    } else {
        decorator = new WiseDecorator(new DefaultElementLocatorFactory(searchContext));
    }
    return decorator;
}

From source file:com.github.wiselenium.Wiselenium.java

License:Open Source License

/**
 * Finds all elements within the search context using the given mechanism. <br/>
 * An empty list will be returned if the elements couldn't be found. <br/>
 * /*  ww w  .  j  av a  2  s.c o m*/
 * @param clazz The class of the elements.
 * @param by The locating mechanism to use.
 * @param searchContext The search context.
 * @return The list of elements.
 * @since 0.3.0
 */
public static <E> List<E> findElements(Class<E> clazz, By by, SearchContext searchContext) {
    List<WebElement> webElements = searchContext.findElements(by);
    if (webElements.isEmpty())
        return Lists.newArrayList();

    WiseDecorator decorator = new WiseDecorator(new DefaultElementLocatorFactory(searchContext));
    return decorator.decorate(clazz, webElements);
}

From source file:com.github.wiselenium.Wiselenium.java

License:Open Source License

/**
 * Decorates a webElement./*  ww w . jav  a 2 s. c o  m*/
 * 
 * @param clazz The class of the decorated element. Must be either WebElement or a type
 * annotated with Component or Frame.
 * @param webElement The webElement that will be decorated.
 * @return The decorated element or null if the type isn't supported.
 * @since 0.3.0
 */
public static <E> E decorateElement(Class<E> clazz, WebElement webElement) {
    WiseDecorator decorator = new WiseDecorator(new DefaultElementLocatorFactory(webElement));
    return decorator.decorate(clazz, webElement);
}

From source file:com.hotwire.selenium.desktop.row.FieldWrapper.java

License:Open Source License

public FieldWrapper(final SearchContext searchContext) {
    super(new DefaultElementLocatorFactory(searchContext));
}

From source file:com.lohika.alp.selenium.AlpPageFactory.java

License:Open Source License

public static void initElements(WebDriver driver, Object page) {
    final WebDriver driverRef = driver;

    ElementLocatorFactory factory;/*from ww  w . j  a v  a  2 s.  c  om*/

    factory = new DefaultElementLocatorFactory(driverRef);

    factory = new LogDescriptionElementLocatorFactory(factory);

    initElements(factory, page);
}

From source file:com.uttesh.selenium.testng.highcharts.HighCharts.java

public HighCharts(WebDriver driver, WebElement chart) {
    PageFactory.initElements(new DefaultElementLocatorFactory(chart), this);
    this.driver = driver;
    this.chart = chart;

    int waitTimeoutInSeconds = 15;
    wait = new WebDriverWait(driver, waitTimeoutInSeconds, 100);
    performAction = new Actions(driver);
}

From source file:org.fluentlenium.core.Fluent.java

License:Apache License

protected <T extends FluentPage> T initClass(Class<T> cls) {
    T page = null;/*ww w.  j ava 2  s .co  m*/
    try {
        Constructor<T> construct = cls.getDeclaredConstructor();
        construct.setAccessible(true);
        page = construct.newInstance();
        Class parent = Class.forName(Fluent.class.getName());
        initDriver(page, parent);
        initBaseUrl(page, parent);

        //init fields with default proxies
        Field[] fields = cls.getDeclaredFields();
        for (Field fieldFromPage : fields) {
            if (!FluentWebElement.class.isAssignableFrom(fieldFromPage.getType())) {
                continue;
            }
            fieldFromPage.setAccessible(true);
            AjaxElement elem = fieldFromPage.getAnnotation(AjaxElement.class);
            if (elem == null) {
                proxyElement(new DefaultElementLocatorFactory(getDriver()), page, fieldFromPage);
            } else {
                proxyElement(new AjaxElementLocatorFactory(getDriver(), elem.timeOutInSeconds()), page,
                        fieldFromPage);
            }
        }
    } catch (ClassNotFoundException e) {
        throw new ConstructionException("Class " + (cls != null ? cls.getName() : " null") + "not found", e);
    } catch (IllegalAccessException e) {
        throw new ConstructionException(
                "IllegalAccessException on class " + (cls != null ? cls.getName() : " null"), e);
    } catch (NoSuchMethodException e) {
        throw new ConstructionException(
                "No constructor found on class " + (cls != null ? cls.getName() : " null"), e);
    } catch (InstantiationException e) {
        throw new ConstructionException("Unable to instantiate " + (cls != null ? cls.getName() : " null"), e);
    } catch (InvocationTargetException e) {
        throw new ConstructionException(
                "Cannot invoke method setDriver on " + (cls != null ? cls.getName() : " null"), e);
    }
    return page;
}

From source file:org.fluentlenium.core.FluentAdapter.java

License:Apache License

private <T extends Fluent> void initFluentWebElements(T page) {
    for (Class classz = page.getClass(); FluentAdapter.class.isAssignableFrom(classz)
            || FluentPage.class.isAssignableFrom(classz); classz = classz.getSuperclass()) {
        for (Field fieldFromPage : classz.getDeclaredFields()) {
            if (isFluentWebElementField(fieldFromPage)) {
                fieldFromPage.setAccessible(true);
                AjaxElement elem = fieldFromPage.getAnnotation(AjaxElement.class);
                if (elem == null) {
                    proxyElement(new DefaultElementLocatorFactory(getDriver()), page, fieldFromPage);
                } else {
                    proxyElement(new AjaxElementLocatorFactory(getDriver(), elem.timeOutInSeconds()), page,
                            fieldFromPage);
                }//from ww  w . jav a2 s. c  o m
            }
        }
    }
}