How to use getEnhancedProxy method of io.appium.java_client.pagefactory.utils.ProxyFactory class

Best io.appium code snippet using io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy

ElementDecorator.java

Source:ElementDecorator.java Github

copy

Full Screen

...26import java.util.Collections;27import java.util.LinkedList;28import java.util.List;29import static io.appium.java_client.internal.ElementMap.getElementClass;30import static io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy;31/**32 * Decorator for custom elements.33 */34public class ElementDecorator extends AppiumFieldDecorator {35 private final Class[] supportedAnnotations = {FindBy.class, FindAll.class, FindBys.class, AndroidFindBy.class,36 iOSXCUITFindBy.class};37 private WebDriver webDriver;38 private int failCount = 0;39 /**40 * Constructor.41 *42 * @param context searchContext to search from43 * @param duration search timeout44 */45 public ElementDecorator(SearchContext context, Duration duration) {46 super(context, duration);47 webDriver = WebDriverUnpackUtility.unpackWebDriverFromSearchContext(context);48 }49 /**50 * Constructor using default timeout.51 *52 * @param context searchContext to search from53 */54 public ElementDecorator(SearchContext context) {55 this(context, DEFAULT_WAITING_TIMEOUT);56 }57 /**58 * Constructor using default timeout.59 *60 * @param loader loader61 * @param field field62 */63 @Override64 public Object decorate(ClassLoader loader, Field field) {65 if (!isDecoratableField(field) && !isDecoratableList(field)) {66 return null;67 }68 ElementLocatorFactory factory;69 try {70 Field factoryFiled = this.getClass().getSuperclass().getDeclaredField("widgetLocatorFactory");71 factoryFiled.setAccessible(true);72 factory = (ElementLocatorFactory) factoryFiled.get(this);73 } catch (NoSuchFieldException | IllegalAccessException e) {74 throw new RuntimeException(e);75 }76 ElementLocator locator = factory.createLocator(field);77 if (locator == null) {78 return null;79 }80 if (BaseElement.class.isAssignableFrom(field.getType())) {81 WebElement webElement = proxyForLocator(locator);82 return createInstance(field.getType(), webElement);83 }84 return decorateList(field, locator);85 }86 /**87 * Проверяет? следует ли является ли поле лимтом и следует ли его декорировать88 *89 * @param field проверяемое поле90 * @return true, если следует декорировать91 * Исключения обрабатываются на стороне вызова92 */93 private boolean isDecoratableList(Field field) {94 if (!List.class.isAssignableFrom(field.getType())) {95 return false;96 }97 Type genericType = field.getGenericType();98 if (!(genericType instanceof ParameterizedType)) {99 return false;100 }101 Class<?> listTypeClass;102 Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];103 try {104 listTypeClass = Class.forName(listType.getTypeName());105 } catch (ClassNotFoundException e) {106 return false;107 }108 if (!BaseElement.class.isAssignableFrom(listTypeClass)) {109 return false;110 }111 return isSupportedAnnotationPresent(field);112 }113 /**114 * Проверяет, следует ли декорировать поле.115 *116 * @param field проверяемое поле117 * @return true, если поле следует декорировать118 */119 private boolean isDecoratableField(Field field) {120 return isSupportedAnnotationPresent(field) && BaseElement.class.isAssignableFrom(field.getType());121 }122 /**123 * Проверяет у поля наличие используемых для поиска элементов аннотаций.124 *125 * @param field проверяемое поле126 * @return true, если аннотация присутствует127 * Исключения обрабатываются на стороне вызова128 */129 @SuppressWarnings("unchecked")130 private boolean isSupportedAnnotationPresent(Field field) {131 for (Class annotation : supportedAnnotations) {132 if (field.getDeclaredAnnotation(annotation) != null) {133 return true;134 }135 }136 return false;137 }138 @SuppressWarnings("unchecked")139 private List<? extends BaseElement> decorateList(Field field, ElementLocator locator) {140 Type genericType = field.getGenericType();141 Class<? extends BaseElement> listTypeClass;142 Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];143 try {144 listTypeClass = (Class<? extends BaseElement>) Class.forName(listType.getTypeName());145 } catch (ClassNotFoundException e) {146 throw new RuntimeException(e);147 }148 List<? extends BaseElement> proxiedList = proxyForListLocator(locator, listTypeClass);149 return Collections.unmodifiableList(proxiedList);150 }151 /**152 * Создание объекта элемента.153 *154 * @param klass объект Class элемента155 * @param element элемент156 * @param <T>157 * @return объект элемента158 */159 @SuppressWarnings("unchecked")160 private <T extends BaseElement> T createInstance(Class<?> klass, WebElement element) {161 try {162 return (T) klass.getConstructor(WebElement.class).newInstance(element);163 } catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {164 throw new RuntimeException(e);165 }166 }167 private WebElement proxyForLocator(ElementLocator locator) {168 try {169 HasSessionDetails webDriver = (HasSessionDetails) this.webDriver;170 ElementInterceptor elementInterceptor = new ElementInterceptor(locator, this.webDriver);171 return getEnhancedProxy(getElementClass(webDriver.getPlatformName(), webDriver.getAutomationName()), elementInterceptor);172 } catch (Exception e) {173 ElementInterceptor elementInterceptor = new ElementInterceptor(locator, this.webDriver);174 return getEnhancedProxy(getElementClass("ARM - htmlunit", ""), elementInterceptor);175 }176 }177 @SuppressWarnings("unchecked")178 private <T extends BaseElement> List<T> proxyForListLocator(ElementLocator locator, Class<T> klass) {179 return (List<T>) Proxy.newProxyInstance(ElementDecorator.class.getClassLoader(),180 new Class[]{List.class},181 new ElementsListInvocationHandler<>(locator, klass));182 }183 /**184 * Infocation handler for list of custom elements.185 *186 * @param <T> type of elements in list187 */188 private final class ElementsListInvocationHandler<T extends BaseElement> implements InvocationHandler {...

Full Screen

Full Screen

AppiumFieldDecorator.java

Source:AppiumFieldDecorator.java Github

copy

Full Screen

...14 * limitations under the License.15 */16package io.appium.java_client.pagefactory;17import static io.appium.java_client.internal.ElementMap.getElementClass;18import static io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy;19import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility20 .unpackWebDriverFromSearchContext;21import com.google.common.collect.ImmutableList;22import io.appium.java_client.HasSessionDetails;23import io.appium.java_client.MobileElement;24import io.appium.java_client.TouchableElement;25import io.appium.java_client.android.AndroidElement;26import io.appium.java_client.ios.IOSElement;27import io.appium.java_client.pagefactory.bys.ContentType;28import io.appium.java_client.pagefactory.locator.CacheableLocator;29import io.appium.java_client.windows.WindowsElement;30import org.openqa.selenium.SearchContext;31import org.openqa.selenium.WebDriver;32import org.openqa.selenium.WebElement;33import org.openqa.selenium.remote.RemoteWebElement;34import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;35import org.openqa.selenium.support.pagefactory.ElementLocator;36import org.openqa.selenium.support.pagefactory.FieldDecorator;37import java.lang.reflect.Constructor;38import java.lang.reflect.Field;39import java.lang.reflect.ParameterizedType;40import java.lang.reflect.Type;41import java.util.ArrayList;42import java.util.List;43import java.util.Map;44import java.util.concurrent.TimeUnit;45import java.util.function.Supplier;46/**47 * Default decorator for use with PageFactory. Will decorate 1) all of the48 * WebElement fields and 2) List of WebElement that have49 * {@literal @AndroidFindBy}, {@literal @AndroidFindBys}, or50 * {@literal @iOSFindBy/@iOSFindBys} annotation with a proxy that locates the51 * elements using the passed in ElementLocatorFactory.52 * Please pay attention: fields of {@link WebElement}, {@link RemoteWebElement},53 * {@link MobileElement}, {@link AndroidElement} and {@link IOSElement} are allowed54 * to use with this decorator55 */56public class AppiumFieldDecorator implements FieldDecorator {57 private static final List<Class<? extends WebElement>> availableElementClasses = ImmutableList.of(WebElement.class,58 RemoteWebElement.class, MobileElement.class, TouchableElement.class, AndroidElement.class,59 IOSElement.class, WindowsElement.class);60 public static long DEFAULT_IMPLICITLY_WAIT_TIMEOUT = 1;61 public static TimeUnit DEFAULT_TIMEUNIT = TimeUnit.SECONDS;62 private final WebDriver originalDriver;63 private final DefaultFieldDecorator defaultElementFieldDecoracor;64 private final AppiumElementLocatorFactory widgetLocatorFactory;65 private final String platform;66 private final String automation;67 private final TimeOutDuration timeOutDuration;68 private final HasSessionDetails hasSessionDetails;69 public AppiumFieldDecorator(SearchContext context, long implicitlyWaitTimeOut,70 TimeUnit timeUnit) {71 this(context, new TimeOutDuration(implicitlyWaitTimeOut, timeUnit));72 }73 /**74 * @param context is an instance of {@link org.openqa.selenium.SearchContext}75 * It may be the instance of {@link org.openqa.selenium.WebDriver}76 * or {@link org.openqa.selenium.WebElement} or77 * {@link io.appium.java_client.pagefactory.Widget} or some other user's78 * extension/implementation.79 * @param timeOutDuration is a desired duration of the waiting for an element presence.80 */81 public AppiumFieldDecorator(SearchContext context, TimeOutDuration timeOutDuration) {82 this.originalDriver = unpackWebDriverFromSearchContext(context);83 if (originalDriver == null84 || !HasSessionDetails.class.isAssignableFrom(originalDriver.getClass())) {85 hasSessionDetails = null;86 platform = null;87 automation = null;88 } else {89 hasSessionDetails = HasSessionDetails.class.cast(originalDriver);90 platform = hasSessionDetails.getPlatformName();91 automation = hasSessionDetails.getAutomationName();92 }93 this.timeOutDuration = timeOutDuration;94 defaultElementFieldDecoracor = new DefaultFieldDecorator(95 new AppiumElementLocatorFactory(context, timeOutDuration, originalDriver,96 new DefaultElementByBuilder(platform, automation))) {97 @Override98 protected WebElement proxyForLocator(ClassLoader ignored, ElementLocator locator) {99 return proxyForAnElement(locator);100 }101 @Override102 @SuppressWarnings("unchecked")103 protected List<WebElement> proxyForListLocator(ClassLoader ignored,104 ElementLocator locator) {105 ElementListInterceptor elementInterceptor = new ElementListInterceptor(locator);106 return getEnhancedProxy(ArrayList.class, elementInterceptor);107 }108 @Override protected boolean isDecoratableList(Field field) {109 if (!List.class.isAssignableFrom(field.getType())) {110 return false;111 }112 Type genericType = field.getGenericType();113 if (!(genericType instanceof ParameterizedType)) {114 return false;115 }116 Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];117 for (Class<? extends WebElement> webElementClass : availableElementClasses) {118 if (webElementClass.equals(listType)) {119 return true;120 }121 }122 return false;123 }124 };125 widgetLocatorFactory =126 new AppiumElementLocatorFactory(context, timeOutDuration, originalDriver,127 new WidgetByBuilder(platform, automation));128 }129 public AppiumFieldDecorator(SearchContext context) {130 this(context, DEFAULT_IMPLICITLY_WAIT_TIMEOUT, DEFAULT_TIMEUNIT);131 }132 /**133 * @param ignored class loader is ignored by current implementation134 * @param field is {@link java.lang.reflect.Field} of page object which is supposed to be135 * decorated.136 * @return a field value or null.137 */138 public Object decorate(ClassLoader ignored, Field field) {139 Object result = defaultElementFieldDecoracor.decorate(ignored, field);140 if (result != null) {141 return result;142 }143 return decorateWidget(field);144 }145 @SuppressWarnings("unchecked")146 private Object decorateWidget(Field field) {147 Class<?> type = field.getType();148 if (!Widget.class.isAssignableFrom(type) && !List.class.isAssignableFrom(type)) {149 return null;150 }151 Class<? extends Widget> widgetType;152 boolean isAlist = false;153 if (List.class.isAssignableFrom(type)) {154 isAlist = true;155 Type genericType = field.getGenericType();156 if (!(genericType instanceof ParameterizedType)) {157 return null;158 }159 Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];160 if (ParameterizedType.class.isAssignableFrom(listType.getClass())) {161 listType = ((ParameterizedType) listType).getRawType();162 }163 if (listType instanceof Class) {164 if (!Widget.class.isAssignableFrom((Class) listType)) {165 return null;166 }167 widgetType = Class.class.cast(listType);168 } else {169 return null;170 }171 } else {172 widgetType = (Class<? extends Widget>) field.getType();173 }174 CacheableLocator locator = widgetLocatorFactory.createLocator(field);175 Map<ContentType, Constructor<? extends Widget>> map =176 OverrideWidgetReader.read(widgetType, field, platform, automation);177 if (isAlist) {178 return getEnhancedProxy(ArrayList.class,179 new WidgetListInterceptor(locator, originalDriver, map, widgetType,180 timeOutDuration));181 }182 Constructor<? extends Widget> constructor =183 WidgetConstructorUtil.findConvenientConstructor(widgetType);184 return getEnhancedProxy(widgetType, new Class[] {constructor.getParameterTypes()[0]},185 new Object[] {proxyForAnElement(locator)},186 new WidgetInterceptor(locator, originalDriver, null, map, timeOutDuration));187 }188 private WebElement proxyForAnElement(ElementLocator locator) {189 ElementInterceptor elementInterceptor = new ElementInterceptor(locator, originalDriver);190 return getEnhancedProxy(getElementClass(hasSessionDetails), elementInterceptor);191 }192}...

Full Screen

Full Screen

SapiumFieldDecorator.java

Source:SapiumFieldDecorator.java Github

copy

Full Screen

1package com.sapium.pagefactory;23import static io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy;4import io.appium.java_client.MobileElement;5import io.appium.java_client.TouchableElement;6import io.appium.java_client.android.AndroidDriver;7import io.appium.java_client.android.AndroidElement;8import io.appium.java_client.ios.IOSDriver;9import io.appium.java_client.ios.IOSElement;10import io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility;1112import java.lang.reflect.Field;13import java.lang.reflect.ParameterizedType;14import java.lang.reflect.Type;15import java.util.ArrayList;16import java.util.HashMap;17import java.util.List;18import java.util.Map;1920import org.openqa.selenium.SearchContext;21import org.openqa.selenium.WebDriver;22import org.openqa.selenium.WebElement;23import org.openqa.selenium.remote.RemoteWebElement;24import org.openqa.selenium.support.pagefactory.ElementLocator;25import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;26import org.openqa.selenium.support.pagefactory.FieldDecorator;2728public class SapiumFieldDecorator implements FieldDecorator {29 private static final List<Class<? extends WebElement>> availableElementClasses =30 new ArrayList<Class<? extends WebElement>>() {31 private static final long serialVersionUID = 1L;32 {33 add(WebElement.class);34 add(RemoteWebElement.class);35 add(MobileElement.class);36 add(TouchableElement.class);37 add(AndroidElement.class);38 add(IOSElement.class);39 }40 };41 42 private final static Map<Class<? extends SearchContext>, Class<? extends WebElement>> elementRuleMap =43 new HashMap<Class<? extends SearchContext>, Class<? extends WebElement>>() {44 private static final long serialVersionUID = 1L;45 {46 put(AndroidDriver.class, AndroidElement.class);47 put(IOSDriver.class, IOSElement.class);48 }49 };50 51 private ElementLocatorFactory factory;52 private final WebDriver originalDriver;5354 public SapiumFieldDecorator(SearchContext context, ElementLocatorFactory factory) {55 this.factory = factory;56 this.originalDriver = WebDriverUnpackUtility.unpackWebDriverFromSearchContext(context);57 }58 59 @Override60 public Object decorate(ClassLoader loader, Field field) {61 if (!(WebElement.class.isAssignableFrom(field.getType())62 || isDecoratableList(field))) {63 return null;64 }65 66 ElementLocator locator = factory.createLocator(field);67 68 if (locator == null) {69 return null;70 }71 72 if (WebElement.class.isAssignableFrom(field.getType())) {73 return proxyForLocator(loader, locator);74 } else if (List.class.isAssignableFrom(field.getType())) {75 return proxyForListLocator(loader, locator);76 } else {77 return null;78 }79 }8081 private boolean isDecoratableList(Field field) {82 if (!List.class.isAssignableFrom(field.getType())) {83 return false;84 }8586 // Type erasure in Java isn't complete. Attempt to discover the generic87 // type of the list.88 Type genericType = field.getGenericType();89 90 if (!(genericType instanceof ParameterizedType)) {91 return false;92 }9394 Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];9596 boolean result = false;97 98 for (Class<? extends WebElement> webElementClass : availableElementClasses) {99 if (!webElementClass.equals(listType)) {100 continue;101 }102 103 result = true;104 break;105 }106 107 return result;108 }109110 private Object proxyForLocator(ClassLoader loader, ElementLocator locator) {111 ElementInterceptor elementInterceptor = new ElementInterceptor(locator, originalDriver);112 return (WebElement) getEnhancedProxy(getTypeForProxy(), elementInterceptor);113 }114 115 private Object proxyForListLocator(ClassLoader loader,116 ElementLocator locator) {117 ElementListInterceptor elementInterceptor = new ElementListInterceptor(locator);118 return getEnhancedProxy(ArrayList.class,119 elementInterceptor);120 }121 122 private Class<?> getTypeForProxy() {123 Class<? extends SearchContext> driverClass = originalDriver.getClass();124 Iterable<Map.Entry<Class<? extends SearchContext>, Class<? extends WebElement>>> rules = elementRuleMap.entrySet();125 //it will return MobileElement subclass when here is something126 for (Map.Entry<Class<? extends SearchContext>, Class<? extends WebElement>> e : rules) {127 //that extends AppiumDriver or MobileElement128 if (e.getKey().isAssignableFrom(driverClass)) {129 return e.getValue();130 }131 } //it is compatible with desktop browser. So at this case it returns RemoteWebElement.class132 return RemoteWebElement.class; ...

Full Screen

Full Screen

AIFieldDecorator.java

Source:AIFieldDecorator.java Github

copy

Full Screen

1package com.globant.aimate.annotation;2import static io.appium.java_client.internal.ElementMap.getElementClass;3import static io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy;4import java.lang.reflect.Field;5import java.lang.reflect.ParameterizedType;6import java.lang.reflect.Type;7import java.lang.reflect.TypeVariable;8import java.time.Duration;9import java.util.ArrayList;10import java.util.Arrays;11import java.util.List;12import org.openqa.selenium.Capabilities;13import org.openqa.selenium.HasCapabilities;14import org.openqa.selenium.SearchContext;15import org.openqa.selenium.WebDriver;16import org.openqa.selenium.WebElement;17import org.openqa.selenium.remote.RemoteWebElement;18import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;19import org.openqa.selenium.support.pagefactory.ElementLocator;20import com.google.common.collect.ImmutableList;21import io.appium.java_client.MobileElement;22import io.appium.java_client.android.AndroidElement;23import io.appium.java_client.internal.CapabilityHelpers;24import io.appium.java_client.ios.IOSElement;25import io.appium.java_client.pagefactory.AppiumFieldDecorator;26import io.appium.java_client.windows.WindowsElement;27public class AIFieldDecorator extends AppiumFieldDecorator {28 29 private static final List<Class<? extends WebElement>> availableElementClasses = ImmutableList.of(WebElement.class,30 RemoteWebElement.class, MobileElement.class, AndroidElement.class,31 IOSElement.class, WindowsElement.class);32 private final DefaultFieldDecorator fieldDecorator;33 private WebDriver webDriver;34 private final String platform;35 private final String automation;36 37 public AIFieldDecorator(SearchContext context) {38 this(context, DEFAULT_WAITING_TIMEOUT);39 }40 public AIFieldDecorator(SearchContext context, Duration duration) {41 super(context, duration);42 43 this.webDriver = (WebDriver) context;44 45 if (this.webDriver instanceof HasCapabilities) {46 Capabilities caps = ((HasCapabilities) this.webDriver).getCapabilities();47 this.platform = CapabilityHelpers.getCapability(caps, "platformName", String.class);48 this.automation = CapabilityHelpers.getCapability(caps, "automationName", String.class);49 } else {50 this.platform = null;51 this.automation = null;52 }53 54 // The magic inside the brackets is overriding proxyForLocator and proxyForListLocator methods of DefaultFieldDecorator class55 fieldDecorator = new DefaultFieldDecorator(new AIElementLocatorFactory(context)) {56 @Override57 protected WebElement proxyForLocator(ClassLoader ignored, ElementLocator locator) {58 AIElementInterceptor elementInterceptor = new AIElementInterceptor(locator, webDriver);59 return getEnhancedProxy(getElementClass(platform, automation), elementInterceptor);60 }61 @Override62 @SuppressWarnings("unchecked")63 protected List<WebElement> proxyForListLocator(ClassLoader ignored,64 ElementLocator locator) {65 AIElementListInterceptor elementInterceptor = new AIElementListInterceptor(locator);66 return getEnhancedProxy(ArrayList.class, elementInterceptor);67 }68 @Override69 protected boolean isDecoratableList(Field field) {70 if (!List.class.isAssignableFrom(field.getType())) {71 return false;72 }73 Type genericType = field.getGenericType();74 if (!(genericType instanceof ParameterizedType)) {75 return false;76 }77 Type listType = ((ParameterizedType) genericType).getActualTypeArguments()[0];78 for (Class<? extends WebElement> webElementClass : availableElementClasses) {79 if (webElementClass.equals(listType)) {80 return true;...

Full Screen

Full Screen

LazyLocatorFactory.java

Source:LazyLocatorFactory.java Github

copy

Full Screen

...69 return RemoteWebElement.class;70 }71 private WebElement proxyForAnElement(ElementLocator locator) {72 ElementInterceptor elementInterceptor = new ElementInterceptor(locator, this.originalDriver);73 return (WebElement) ProxyFactory.getEnhancedProxy(this.getTypeForProxy(), elementInterceptor);74 }75}...

Full Screen

Full Screen

WidgetListInterceptor.java

Source:WidgetListInterceptor.java Github

copy

Full Screen

...65 ContentType type = getCurrentContentType(element);66 Class<?>[] params =67 new Class<?>[] {instantiationMap.get(type).getParameterTypes()[0]};68 cachedWidgets.add(ProxyFactory69 .getEnhancedProxy(declaredType, params, new Object[] {element},70 new WidgetInterceptor(null, driver, element, instantiationMap, duration)));71 }72 }73 try {74 return method.invoke(cachedWidgets, args);75 } catch (Throwable t) {76 throw ThrowableUtil.extractReadableException(t);77 }78 }79} ...

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1import org.openqa.selenium.WebElement;2import org.openqa.selenium.remote.DesiredCapabilities;3import org.openqa.selenium.support.pagefactory.ElementLocator;4import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;5import org.openqa.selenium.support.pagefactory.FieldDecorator;6import org.openqa.selenium.support.ui.ExpectedConditions;7import org.openqa.selenium.support.ui.WebDriverWait;8import io.appium.java_client.pagefactory.AppiumFieldDecorator;9import io.appium.java_client.pagefactory.AppiumFieldDecorator.ProxyFactory;10import io.appium.java_client.pagefactory.iOSFindBy;11import io.appium.java_client.pagefactory.iOSXCUITFindBy;12import io.appium.java_client.pagefactory.utils.ProxyFactory;13import io.appium.java_client.remote.MobileCapabilityType;14import io.appium.java_client.remote.MobilePlatform;15import io.appium.java_client.remote.AutomationName;16public class AppiumTest {17 public static void main(String[] args) throws Exception {18 DesiredCapabilities capabilities = new DesiredCapabilities();19 capabilities.setCapability("platformName", MobilePlatform.IOS);20 capabilities.setCapability("platformVersion", "9.3");21 capabilities.setCapability("deviceName", "iPhone 6");22 capabilities.setCapability("app", "/Users/xyz/Downloads/xyz.app");23 capabilities.setCapability("noReset", true);24 capabilities.setCapability("automationName", AutomationName.IOS_XCUI_TEST);25 capabilities.setCapability("newCommandTimeout", 60);

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.pagefactory.AppiumFieldDecorator;2import io.appium.java_client.pagefactory.utils.ProxyFactory;3import org.openqa.selenium.WebDriver;4import org.openqa.selenium.support.PageFactory;5public class AppiumFieldDecoratorTest {6 public static void main(String[] args) {7 WebDriver driver = null;8 AppiumFieldDecorator decorator = new AppiumFieldDecorator(driver);9 ProxyFactory proxyFactory = new ProxyFactory();10 proxyFactory.setEnhancer(new Enhancer());11 proxyFactory.setSuperclass(MyElement.class);12 MyElement element = (MyElement) proxyFactory.getEnhancedProxy();13 System.out.println(element);14 }15}16import io.appium.java_client.pagefactory.AppiumFieldDecorator;17import io.appium.java_client.pagefactory.utils.ProxyFactory;18import org.openqa.selenium.WebDriver;19import org.openqa.selenium.support.PageFactory;20import org.openqa.selenium.support.pagefactory.ElementLocator;21public class AppiumFieldDecoratorTest {22 public static void main(String[] args) {23 WebDriver driver = null;24 AppiumFieldDecorator decorator = new AppiumFieldDecorator(driver);25 ProxyFactory proxyFactory = new ProxyFactory();26 proxyFactory.setEnhancer(new Enhancer());27 proxyFactory.setSuperclass(MyElement.class);28 MyElement element = (MyElement) proxyFactory.getEnhancedProxy();29 System.out.println(element);30 }31}32import io.appium.java_client.pagefactory.AppiumFieldDecorator;33import io.appium.java_client.pagefactory.utils.ProxyFactory;34import org.openqa.selenium.WebDriver;35import org.openqa.selenium.support.PageFactory;36import org.openqa.selenium.support.pagefactory.ElementLocator;37public class AppiumFieldDecoratorTest {38 public static void main(String[] args) {39 WebDriver driver = null;40 AppiumFieldDecorator decorator = new AppiumFieldDecorator(driver);41 ProxyFactory proxyFactory = new ProxyFactory();42 proxyFactory.setEnhancer(new Enhancer());43 proxyFactory.setSuperclass(MyElement.class);44 MyElement element = (MyElement) proxyFactory.getEnhancedProxy();45 System.out.println(element);46 }47}

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.pagefactory.utils.ProxyFactory;2import org.openqa.selenium.WebElement;3import org.openqa.selenium.support.pagefactory.ElementLocator;4public class AppiumPageFactory {5 public static <T> T initElements(EnhancedAppiumDriver driver, Class<T> pageClassToProxy) {6 T page = ProxyFactory.getEnhancedProxy(driver, pageClassToProxy);7 initElements(new AppiumFieldDecorator(driver), page);8 return page;9 }10 public static void initElements(EnhancedAppiumDriver driver, Object page) {11 initElements(new AppiumFieldDecorator(driver), page);12 }13 public static void initElements(EnhancedAppiumDriver driver, Object page, long timeOutInSeconds) {14 initElements(new AppiumFieldDecorator(driver, timeOutInSeconds), page);15 }16 public static void initElements(AppiumFieldDecorator decorator, Object page) {17 Class<?> proxyIn = page.getClass();18 while (proxyIn != Object.class) {19 proxyFields(decorator, page, proxyIn);20 proxyIn = proxyIn.getSuperclass();21 }22 }23 private static void proxyFields(AppiumFieldDecorator decorator, Object page, Class<?> proxyIn) {24 Field[] fields = proxyIn.getDeclaredFields();25 for (Field field : fields) {26 if (!field.isAnnotationPresent(FindBy.class) && !field.isAnnotationPresent(FindBys.class) && !field.isAnnotationPresent(FindAll.class)) {27 continue;28 }29 ElementLocator locator = decorator.createLocator(field);30 if (locator == null) {31 continue;32 }33 if (List.class.isAssignableFrom(field.getType())) {34 Class<?> genericType = (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];35 if (WebElement.class.isAssignableFrom(genericType)) {36 try {37 field.set(page, decorator.createWebElementList(locator));38 } catch (IllegalAccessException e) {39 throw new RuntimeException(e);40 }41 } else {42 try {43 field.set(page, decorator.createMobileElementList(locator, genericType));44 } catch (IllegalAccessException e) {45 throw new RuntimeException(e);46 }47 }48 } else {49 if (WebElement.class.isAssignableFrom(field.getType())) {50 try {51 field.set(page, decorator.createWebElement(locator));52 } catch (IllegalAccessException e) {53 throw new RuntimeException(e);

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.pagefactory.AppiumFieldDecorator;2import io.appium.java_client.pagefactory.utils.ProxyFactory;3import org.openqa.selenium.WebElement;4import org.openqa.selenium.support.FindBy;5import org.openqa.selenium.support.PageFactory;6public class GetEnhancedProxy {7 @FindBy(id = "android:id/text1")8 private WebElement element1;9 public GetEnhancedProxy() {10 PageFactory.initElements(new AppiumFieldDecorator(driver), this);11 }12 public WebElement getElement1() {13 return ProxyFactory.getEnhancedProxy(element1, WebElement.class);14 }15}16import org.testng.Assert;17import org.testng.annotations.Test;18public class TestEnhancedProxy extends BaseTest {19 public void testEnhancedProxy() {20 GetEnhancedProxy getEnhancedProxy = new GetEnhancedProxy();21 Assert.assertTrue(getEnhancedProxy.getElement1().isDisplayed());22 }23}

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1ProxyFactory factory = new ProxyFactory(driver);2factory.setEnhance(true);3factory.setSuperclass(driver.getClass());4WebDriver proxyDriver = (WebDriver)factory.getEnhancedProxy();5WebElement element = driver.findElement(By.id("id"));6ProxyFactory factory = new ProxyFactory(element);7factory.setEnhance(true);8factory.setSuperclass(element.getClass());9WebElement proxyElement = (WebElement)factory.getEnhancedProxy();10ProxyFactory factory = new ProxyFactory(driver);11factory.setEnhance(true);12factory.setSuperclass(driver.getClass());13AndroidDriver proxyDriver = (AndroidDriver)factory.getEnhancedProxy();14AndroidElement element = driver.findElementByAndroidUIAutomator("text(\"text\")");15ProxyFactory factory = new ProxyFactory(element);16factory.setEnhance(true);17factory.setSuperclass(element.getClass());18AndroidElement proxyElement = (AndroidElement)factory.getEnhancedProxy();19ProxyFactory factory = new ProxyFactory(driver);20factory.setEnhance(true);21factory.setSuperclass(driver.getClass());22IOSDriver proxyDriver = (IOSDriver)factory.getEnhancedProxy();23IOSElement element = driver.findElementByIosUIAutomation("UIATarget.localTarget().frontMostApp

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1public class AppiumJavaClient {2 public static void main(String[] args) {3 ProxyFactory factory = new ProxyFactory();4 RemoteWebDriver driver = new RemoteWebDriver();5 RemoteWebDriver enhancedProxy = factory.getEnhancedProxy(driver);6 }7}8{9 public static void Main(string[] args)10 {11 ProxyFactory factory = new ProxyFactory();12 RemoteWebDriver driver = new RemoteWebDriver();13 RemoteWebDriver enhancedProxy = factory.GetEnhancedProxy(driver);14 }15}16var appium = require('appium');17var factory = new appium.ProxyFactory();18var driver = new appium.RemoteWebDriver();19var enhancedProxy = factory.getEnhancedProxy(driver);20from appium import ProxyFactory21factory = ProxyFactory()22driver = RemoteWebDriver()23enhancedProxy = factory.getEnhancedProxy(driver)24enhancedProxy = factory.getEnhancedProxy(driver)25use Appium\PageObjects\ProxyFactory;26$factory = new ProxyFactory();27$driver = new RemoteWebDriver();28$enhancedProxy = $factory->getEnhancedProxy($driver);

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1AppiumDriver driver = new AndroidDriver();2PageFactory.initElements(new AppiumFieldDecorator(driver), this);3AppiumDriver driver = new AndroidDriver();4PageFactory.initElements(new AppiumElementLocatorFactory(driver), this);5AppiumDriver driver = new AndroidDriver();6PageFactory.initElements(new AppiumElementLocatorFactory(driver), this);7AppiumDriver driver = new AndroidDriver();8PageFactory.initElements(new AppiumFieldDecorator(driver), this);9AppiumDriver driver = new AndroidDriver();10PageFactory.initElements(new AppiumElementLocatorFactory(driver), this);11AppiumDriver driver = new AndroidDriver();12PageFactory.initElements(new AppiumElementLocatorFactory(driver), this);13AppiumDriver driver = new AndroidDriver();14PageFactory.initElements(new Appium

Full Screen

Full Screen

getEnhancedProxy

Using AI Code Generation

copy

Full Screen

1package appium;2import java.net.MalformedURLException;3import java.net.URL;4import org.openqa.selenium.remote.DesiredCapabilities;5import io.appium.java_client.android.AndroidDriver;6import io.appium.java_client.pagefactory.AppiumFieldDecorator;7import io.appium.java_client.pagefactory.TimeOutDuration;8import io.appium.java_client.pagefactory.WithTimeout;9import io.appium.java_client.pagefactory.utils.ProxyFactory;10import io.appium.java_client.pagefactory.AndroidFindBy;11import io.appium.java_client.pagefactory.AppiumFieldDecorator;12import io.appium.java_client.pagefactory.TimeOutDuration;13import io.appium.java_client.pagefactory.WithTimeout;14import io.appium.java_client.pagefactory.utils.ProxyFactory;15import io.appium.java_client.android.AndroidDriver;16import io.appium.java_client.android.AndroidElement;17public class appium {18public static void main(String[] args) throws MalformedURLException, InterruptedException {19DesiredCapabilities capabilities = new DesiredCapabilities();20capabilities.setCapability("deviceName", "Android Emulator");21capabilities.setCapability("platformName", "Android");22capabilities.setCapability("appPackage", "com.android.calculator2");23capabilities.setCapability("appActivity", "com.android.calculator2.Calculator");

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run io.appium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in ProxyFactory

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful