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;
}
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);
}
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;
}
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;
}
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);
}
Aggregations