List of usage examples for org.openqa.selenium.support.pagefactory FieldDecorator decorate
Object decorate(ClassLoader loader, Field field);
From source file:com.github.wiselenium.factory.WisePageFactory.java
License:Open Source License
private static void proxyElements(SearchContext searchContext, Object instance, Class<?> instanceHierarchyClass) { Field[] fields = instanceHierarchyClass.getDeclaredFields(); for (Field field : fields) { if (field.isSynthetic()) continue; FieldDecorator decorator = initDecorator(searchContext, field); Object value = decorator.decorate(instance.getClass().getClassLoader(), field); if (value != null) { try { field.setAccessible(true); field.set(instance, value); } catch (IllegalAccessException e) { throw new ElementInitializationException(field, instance.getClass(), e); }/* w w w .ja va 2s. c om*/ } } }
From source file:com.oracle.pgbu.common.pagefactory.CustomPageFactory.java
License:Apache License
private synchronized static void proxyFields(FieldDecorator decorator, Object page, Class<?> proxyIn) { Field[] fields = proxyIn.getDeclaredFields(); for (Field field : fields) { if (field.getAnnotations().length == 0) { continue; }//from ww w . j av a2 s . c om Object value = decorator.decorate(page.getClass().getClassLoader(), field); if (value != null) { try { field.setAccessible(true); if ((field.getType() != WebElement.class)) { // value returned is always of type WebElement. // so, if the Field type is not WebElement, get the // type and create a new instance of the class by // reflection. Class<?> objectClass = Class.forName(field.getType().getName().toString()); Constructor<?> constructor = objectClass.getConstructor(new Class[] { WebElement.class }); Object newVal = (constructor.newInstance((WebElement) value)); field.set(page, newVal); } else { field.set(page, value); } } catch (Exception e) { throw new RuntimeException(e); } } } }
From source file:org.alfresco.po.share.FactorySharePage.java
License:Open Source License
/** * Applies proxy and injects spring awareness to fields. * @param decorator/* w ww .java 2 s . c o m*/ * @param page * @param proxyIn */ private void proxyFields(FieldDecorator decorator, Object page, Class<?> proxyIn) { Field[] fields = proxyIn.getDeclaredFields(); for (Field field : fields) { Object value = decorator.decorate(page.getClass().getClassLoader(), field); if (value != null) { try { field.setAccessible(true); if (value instanceof PageElement) { //Wire spring ac.getAutowireCapableBeanFactory().autowireBean(value); ((PageElement) value).setDefaultWaitTime(defaultWaitTime); ((PageElement) value).setMaxPageLoadingTime(maxPageLoadingTime); } field.set(page, value); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } } }