List of usage examples for org.openqa.selenium.support.pagefactory ElementLocatorFactory createLocator
ElementLocator createLocator(Field field);
From source file:org.fluentlenium.core.Fluent.java
License:Apache License
private static void proxyElement(ElementLocatorFactory factory, Object page, Field field) { ElementLocator locator = factory.createLocator(field); if (locator == null) { return;//from w w w . ja va2 s . co m } InvocationHandler handler = new LocatingElementHandler(locator); WebElement proxy = (WebElement) java.lang.reflect.Proxy.newProxyInstance(page.getClass().getClassLoader(), new Class[] { WebElement.class }, handler); try { field.setAccessible(true); field.set(page, new FluentWebElement(proxy)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
From source file:org.fluentlenium.core.FluentAdapter.java
License:Apache License
private static void proxyElement(ElementLocatorFactory factory, Object page, Field field) { ElementLocator locator = factory.createLocator(field); if (locator == null) { return;// ww w . ja v a 2 s . com } try { field.setAccessible(true); if (isFluentList(field)) { // LocatingElementListHandler is not a good choice, elements are FluentWebElement not WebElement. final InvocationHandler handler = new FluentListInvocationHandler(locator); FluentList<FluentWebElement> proxy = (FluentList<FluentWebElement>) Proxy.newProxyInstance( page.getClass().getClassLoader(), new Class[] { FluentList.class }, handler); field.set(page, proxy); } else { final InvocationHandler handler = new LocatingElementHandler(locator); WebElement proxy = (WebElement) Proxy.newProxyInstance(page.getClass().getClassLoader(), new Class[] { WebElement.class }, handler); field.set(page, field.getType().getConstructor(WebElement.class).newInstance(proxy)); } } catch (Exception e) { throw new RuntimeException( "Unable to find an accessible constructor with an argument of type WebElement in " + field.getType(), e); } }
From source file:org.fluentlenium.core.test.FluentTest.java
License:Apache License
private static void proxyElement(ElementLocatorFactory factory, Object page, Field field) { ElementLocator locator = factory.createLocator(field); if (locator == null) { return;/*from w w w.jav a 2 s .c o m*/ } InvocationHandler handler = new LocatingElementHandler(locator); WebElement proxy = (WebElement) Proxy.newProxyInstance(page.getClass().getClassLoader(), new Class[] { WebElement.class }, handler); try { field.setAccessible(true); field.set(page, new FluentWebElement(proxy)); } catch (IllegalAccessException e) { throw new RuntimeException(e); } }