Search in sources :

Example 1 with LocatingElementHandler

use of org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler in project carina by qaprosoft.

the class ExtendedFieldDecorator method proxyForAbstractUIObject.

@SuppressWarnings("unchecked")
protected <T extends AbstractUIObject> T proxyForAbstractUIObject(ClassLoader loader, Field field, ElementLocator locator) {
    ((ExtendedElementLocator) locator).setShouldCache(false);
    InvocationHandler handler = new LocatingElementHandler(locator);
    WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[] { WebElement.class, WrapsElement.class, Locatable.class }, handler);
    Class<? extends AbstractUIObject> clazz = (Class<? extends AbstractUIObject>) field.getType();
    T uiObject;
    try {
        uiObject = (T) clazz.getConstructor(WebDriver.class, SearchContext.class).newInstance(webDriver, proxy);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Implement appropriate AbstractUIObject constructor for auto-initialization!", e);
    } catch (Exception e) {
        throw new RuntimeException("Error creating UIObject!", e);
    }
    uiObject.setName(field.getName());
    uiObject.setRootElement(proxy);
    uiObject.setRootBy(getLocatorBy(locator));
    return uiObject;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) LocatingElementHandler(org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler) SearchContext(org.openqa.selenium.SearchContext) WebElement(org.openqa.selenium.WebElement) InvocationHandler(java.lang.reflect.InvocationHandler) WrapsElement(org.openqa.selenium.internal.WrapsElement) AbstractUIObject(com.qaprosoft.carina.core.gui.AbstractUIObject) ExtendedElementLocator(com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedElementLocator) Locatable(org.openqa.selenium.interactions.internal.Locatable)

Example 2 with LocatingElementHandler

use of org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler in project carina by qaprosoft.

the class ExtendedFieldDecorator method proxyForLocator.

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) || field.isAnnotationPresent(ExtendedFindBy.class) ? new LocalizedAnnotations(field).buildBy() : null);
}
Also used : LocalizedAnnotations(com.qaprosoft.carina.core.foundation.webdriver.locator.LocalizedAnnotations) ExtendedFindBy(com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy) LocatingElementHandler(org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler) WebElement(org.openqa.selenium.WebElement) InvocationHandler(java.lang.reflect.InvocationHandler) WrapsElement(org.openqa.selenium.internal.WrapsElement) ExtendedFindBy(com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy) FindBy(org.openqa.selenium.support.FindBy) Locatable(org.openqa.selenium.interactions.internal.Locatable)

Example 3 with LocatingElementHandler

use of org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler in project seleniumRobot by bhecquet.

the class SeleniumNativeActions method getFrameElement.

/**
 * Returns a FrameElement based on the object passed in argument
 * @param frameArg
 * @return
 * @throws SecurityException
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 * @throws IllegalArgumentException
 */
private FrameElement getFrameElement(Object frameArg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
    FrameElement frameEl = null;
    if (frameArg instanceof HtmlElement) {
        frameEl = new FrameElement("", ((HtmlElement) frameArg).getBy());
    } else if (frameArg instanceof WebElement && frameArg.getClass().getName().contains("Proxy")) {
        LocatingElementHandler locatingEh = (LocatingElementHandler) Proxy.getInvocationHandler(frameArg);
        Field locatorField = LocatingElementHandler.class.getDeclaredField("locator");
        locatorField.setAccessible(true);
        DefaultElementLocator locator = ((DefaultElementLocator) locatorField.get(locatingEh));
        Field byField = DefaultElementLocator.class.getDeclaredField("by");
        byField.setAccessible(true);
        frameEl = new FrameElement("", (By) byField.get(locator));
    } else if (frameArg instanceof By) {
        frameEl = new FrameElement("", (By) frameArg);
    } else if (frameArg instanceof Integer) {
        frameEl = new FrameElement("", By.tagName("iframe"), (Integer) frameArg);
    } else if (frameArg instanceof String) {
        String name = ((String) frameArg).replaceAll("(['\"\\\\#.:;,!?+<>=~*^$|%&@`{}\\-/\\[\\]\\(\\)])", "\\\\$1");
        frameEl = new FrameElement("", By.cssSelector("frame[name='" + name + "'],iframe[name='" + name + "'],frame#" + name + ",iframe#" + name));
    }
    return frameEl;
}
Also used : Field(java.lang.reflect.Field) DefaultElementLocator(org.openqa.selenium.support.pagefactory.DefaultElementLocator) LocatingElementHandler(org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler) HtmlElement(com.seleniumtests.uipage.htmlelements.HtmlElement) By(org.openqa.selenium.By) FrameElement(com.seleniumtests.uipage.htmlelements.FrameElement) WebElement(org.openqa.selenium.WebElement)

Example 4 with LocatingElementHandler

use of org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler in project carina by zebrunner.

the class ExtendedFieldDecorator method proxyForAbstractUIObject.

@SuppressWarnings("unchecked")
protected <T extends AbstractUIObject> T proxyForAbstractUIObject(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);
    Class<? extends AbstractUIObject> clazz = (Class<? extends AbstractUIObject>) field.getType();
    T uiObject;
    try {
        uiObject = (T) clazz.getConstructor(WebDriver.class, SearchContext.class).newInstance(webDriver, proxy);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("Implement appropriate AbstractUIObject constructor for auto-initialization!", e);
    } catch (Exception e) {
        throw new RuntimeException("Error creating UIObject!", e);
    }
    uiObject.setName(field.getName());
    uiObject.setRootElement(proxy);
    uiObject.setRootBy(getLocatorBy(locator));
    return uiObject;
}
Also used : WebDriver(org.openqa.selenium.WebDriver) LocatingElementHandler(org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler) SearchContext(org.openqa.selenium.SearchContext) WebElement(org.openqa.selenium.WebElement) InvocationHandler(java.lang.reflect.InvocationHandler) WrapsElement(org.openqa.selenium.internal.WrapsElement) AbstractUIObject(com.qaprosoft.carina.core.gui.AbstractUIObject) Locatable(org.openqa.selenium.interactions.internal.Locatable)

Example 5 with LocatingElementHandler

use of org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler in project carina by zebrunner.

the class ExtendedFieldDecorator method proxyForLocator.

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) || field.isAnnotationPresent(ExtendedFindBy.class) ? new LocalizedAnnotations(field).buildBy() : null);
}
Also used : LocalizedAnnotations(com.qaprosoft.carina.core.foundation.webdriver.locator.LocalizedAnnotations) ExtendedFindBy(com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy) LocatingElementHandler(org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler) WebElement(org.openqa.selenium.WebElement) InvocationHandler(java.lang.reflect.InvocationHandler) WrapsElement(org.openqa.selenium.internal.WrapsElement) ExtendedFindBy(com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy) FindBy(org.openqa.selenium.support.FindBy) Locatable(org.openqa.selenium.interactions.internal.Locatable)

Aggregations

WebElement (org.openqa.selenium.WebElement)5 LocatingElementHandler (org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler)5 InvocationHandler (java.lang.reflect.InvocationHandler)4 Locatable (org.openqa.selenium.interactions.internal.Locatable)4 WrapsElement (org.openqa.selenium.internal.WrapsElement)4 ExtendedFindBy (com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy)2 LocalizedAnnotations (com.qaprosoft.carina.core.foundation.webdriver.locator.LocalizedAnnotations)2 AbstractUIObject (com.qaprosoft.carina.core.gui.AbstractUIObject)2 SearchContext (org.openqa.selenium.SearchContext)2 WebDriver (org.openqa.selenium.WebDriver)2 FindBy (org.openqa.selenium.support.FindBy)2 ExtendedElementLocator (com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedElementLocator)1 FrameElement (com.seleniumtests.uipage.htmlelements.FrameElement)1 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)1 Field (java.lang.reflect.Field)1 By (org.openqa.selenium.By)1 DefaultElementLocator (org.openqa.selenium.support.pagefactory.DefaultElementLocator)1