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

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

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 */...

Full Screen

Full Screen

AppiumFieldDecorator.java

Source:AppiumFieldDecorator.java Github

copy

Full Screen

...13 * See the License for the specific language governing permissions and14 * limitations under the License.15 */16package io.appium.java_client.pagefactory;17import static io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy;18import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility.getAutomation;19import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility.getPlatform;20import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility21 .unpackWebDriverFromSearchContext;22import io.appium.java_client.MobileElement;23import io.appium.java_client.TouchableElement;24import io.appium.java_client.android.AndroidDriver;25import io.appium.java_client.android.AndroidElement;26import io.appium.java_client.ios.IOSDriver;27import io.appium.java_client.ios.IOSElement;28import io.appium.java_client.pagefactory.bys.ContentType;29import io.appium.java_client.pagefactory.locator.CacheableLocator;30import org.openqa.selenium.SearchContext;31import org.openqa.selenium.WebDriver;...

Full Screen

Full Screen

DefaultFieldDecorator.java

Source:DefaultFieldDecorator.java Github

copy

Full Screen

...67 Duration.ofSeconds(FrameworkConfig.get().implicitlywait()),68 new DefaultElementByBuilder("android",69 "this.automation"));70 InvocationHandler handler = new ElementListProxyHandler(PageFactoryUtils.getGenericParameterClass(field), locator.createLocator(field), PageFactoryUtils.getElementName(field));71 return ProxyFactory.creatElementListProxy(loader, handler);72 }73 /**74 * Декорирование списка коллекций(одинаковые элементы, содержащие одинаковые элементы) ( List<T extends ICollectionPageObject>>)75 *76 * @param loader - загрузчик классов77 * @param field - reflection поле PageObject78 * @return - proxy объект, который будет создан при первом обращении к нему79 */80 private Object decorateElementCollection(ClassLoader loader, Field field) {81 AppiumElementLocatorFactory locator = new AppiumElementLocatorFactory(82 searchContext,83 Duration.ofSeconds(FrameworkConfig.get().implicitlywait()),84 new DefaultElementByBuilder("android", "automation")85 );86 InvocationHandler handler = new CollectionProxyHandler(PageFactoryUtils.getGenericParameterClass(field), locator.createLocator(field), PageFactoryUtils.getElementName(field));87 return ProxyFactory.createElementCollectionProxy(loader, handler);88 }89 private WebElement proxyWebElement(ClassLoader loader, Field field) {90 AppiumElementLocatorFactory locator = new AppiumElementLocatorFactory(91 searchContext,92 Duration.ofSeconds(FrameworkConfig.get().implicitlywait()),93 new DefaultElementByBuilder("android", "automation")94 );95 InvocationHandler handler = new ElementProxyHandler(locator.createLocator(field), field.getName());96 return ProxyFactory.createWebElementProxy(loader, handler);97 }98}...

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; ...

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;...

Full Screen

Full Screen

LazyLocatorFactory.java

Source:LazyLocatorFactory.java Github

copy

Full Screen

...9import io.appium.java_client.pagefactory.AppiumFieldDecorator;10import io.appium.java_client.pagefactory.TimeOutDuration;11import io.appium.java_client.pagefactory.Widget;12import io.appium.java_client.pagefactory.locator.CacheableLocator;13import io.appium.java_client.pagefactory.utils.ProxyFactory;14import io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility;15import org.openqa.selenium.SearchContext;16import org.openqa.selenium.WebDriver;17import org.openqa.selenium.WebElement;18import org.openqa.selenium.remote.RemoteWebElement;19import org.openqa.selenium.support.pagefactory.DefaultFieldDecorator;20import org.openqa.selenium.support.pagefactory.ElementLocator;21import java.lang.reflect.Constructor;22import java.lang.reflect.Field;23import java.lang.reflect.ParameterizedType;24import java.lang.reflect.Type;25import java.util.*;26import java.util.concurrent.TimeUnit;27public class LazyLocatorFactory extends AppiumFieldDecorator {28 private final LazyMobileContext searchContext;29 public static TimeUnit DEFAULT_TIMEUNIT;30 public LazyLocatorFactory(LazyMobileContext searchContext) {31 super(searchContext);32 this.searchContext = searchContext;33 }34 private static final List<Class<? extends WebElement>> availableElementClasses = new ArrayList() {35 private static final long serialVersionUID = 1L;36 {37 this.add(WebElement.class);38 this.add(RemoteWebElement.class);39 this.add(MobileElement.class);40 this.add(TouchableElement.class);41 this.add(AndroidElement.class);42 this.add(IOSElement.class);43 }44 };45 private static final Map<Class<? extends SearchContext>, Class<? extends WebElement>> elementRuleMap = new HashMap() {46 private static final long serialVersionUID = 1L;47 {48 this.put(AndroidDriver.class, AndroidElement.class);49 this.put(IOSDriver.class, IOSElement.class);50 }51 };52 static {53 DEFAULT_TIMEUNIT = TimeUnit.SECONDS;54 }55 public Object decorate(ClassLoader ignored, Field field) {56 Object result = this.defaultElementFieldDecoracor.decorate(ignored, field);57 return result != null ? result : this.decorateWidget(field);58 }59 private Class<?> getTypeForProxy() {60 Class driverClass = this.originalDriver.getClass();61 Set rules = elementRuleMap.entrySet();62 Iterator var4 = rules.iterator();63 while (var4.hasNext()) {64 Map.Entry e = (Map.Entry) var4.next();65 if (((Class) e.getKey()).isAssignableFrom(driverClass)) {66 return (Class) e.getValue();67 }68 }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

...31import io.appium.java_client.pagefactory.Widget;32import io.appium.java_client.pagefactory.bys.ContentType;33import io.appium.java_client.pagefactory.interceptors.InterceptorOfAListOfElements;34import io.appium.java_client.pagefactory.locator.CacheableLocator;35import io.appium.java_client.pagefactory.utils.ProxyFactory;3637class WidgetListInterceptor extends InterceptorOfAListOfElements {3839 private List<WebElement> cachedElements;40 private final List<Widget> cachedWidgets = new ArrayList<>();41 private final Class<? extends Widget> declaredType;42 private final WebDriver driver;43 private final TimeOutDuration duration;44 private final Map<ContentType, Constructor<? extends Widget>> instantiationMap;4546 WidgetListInterceptor(CacheableLocator locator, WebDriver driver,47 Map<ContentType, Constructor<? extends Widget>> instantiationMap,48 Class<? extends Widget> declaredType, TimeOutDuration duration) {49 super(locator);50 this.instantiationMap = instantiationMap;51 this.declaredType = declaredType;52 this.duration = duration;53 this.driver = driver;54 }555657 @Override protected Object getObject(List<WebElement> elements, Method method, Object[] args)58 throws Throwable {59 if (cachedElements == null || locator != null && !((CacheableLocator) locator)60 .isLookUpCached()) {61 cachedElements = elements;62 cachedWidgets.clear();6364 for (WebElement element : cachedElements) {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

ProxyFactory

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.support.PageFactory;4import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;5import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;6import org.openqa.selenium.support.pagefactory.FieldDecorator;7import org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler;8import java.lang.reflect.InvocationHandler;9import java.lang.reflect.Method;10import java.lang.reflect.Proxy;11import io.appium.java_client.pagefactory.AppiumElementLocatorFactory;12public class ProxyFactoryExample {13 public static void main(String[] args) {14 MyPageObjectClass myPageObjectClass = new MyPageObjectClass();15 MyInvocationHandler myInvocationHandler = new MyInvocationHandler(myPageObjectClass);16 ProxyFactory proxyFactory = new ProxyFactory();17 proxyFactory.setHandler(myInvocationHandler);18 proxyFactory.setProxyClass(MyPageObjectClass.class);19 MyPageObjectClass myPageObjectClassProxy = (MyPageObjectClass) proxyFactory.create();20 myPageObjectClassProxy.myMethod();21 }22}23import io.appium.java_client.pagefactory.AppiumFieldDecorator;24import io.appium.java_client.pagefactory.utils.ProxyFactory;25import org.openqa.selenium.support.PageFactory;26import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;27import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;28import org.openqa.selenium.support.pagefactory.FieldDecorator;29import org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler;30import java.lang.reflect.InvocationHandler;31import java.lang.reflect.Method;32import java.lang.reflect.Proxy;33import io.appium.java_client.pagefactory.AppiumElementLocatorFactory;34public class PageFactoryExample {35 public static void main(String[] args) {

Full Screen

Full Screen

ProxyFactory

Using AI Code Generation

copy

Full Screen

1ProxyFactory factory = new ProxyFactory(new AppiumFieldDecorator(driver), PageObject.class);2PageObject page = factory.create(PageObject.class);3public AppiumFieldDecorator(AppiumDriver driver, int timeOutInSeconds) {4 this(driver, timeOutInSeconds, DEFAULT_SLEEP_TIMEOUT);5}6public AppiumFieldDecorator(AppiumDriver driver, int timeOutInSeconds, int sleepInMillis) {7 this.driver = driver;8 this.timeOutInSeconds = timeOutInSeconds;9 this.sleepInMillis = sleepInMillis;10}11public AppiumFieldDecorator(AppiumDriver driver) {12 this(driver, DEFAULT_TIME_OUT, DEFAULT_SLEEP_TIMEOUT);13}14public AppiumFieldDecorator(AppiumDriver driver, int timeOutInSeconds, int sleepInMillis, boolean enableAppiumAnnotations) {15 this(driver, timeOutInSeconds, sleepInMillis);16 this.enableAppiumAnnotations = enableAppiumAnnotations;17}18public AppiumFieldDecorator(AppiumDriver driver, boolean enableAppiumAnnotations) {19 this(driver, DEFAULT_TIME_OUT, DEFAULT_SLEEP_TIMEOUT, enableAppiumAnnotations);20}21public AppiumFieldDecorator(AppiumDriver driver, int timeOutInSeconds, int sleepInMillis, boolean enableAppiumAnnotations, boolean enableJavascriptAnnotations) {22 this(driver, timeOutInSeconds, sleepInMillis, enableAppiumAnnotations);23 this.enableJavascriptAnnotations = enableJavascriptAnnotations;24}25public AppiumFieldDecorator(AppiumDriver driver, boolean enableAppiumAnnotations, boolean enableJavascriptAnnotations) {26 this(driver, DEFAULT_TIME_OUT, DEFAULT_SLEEP_TIMEOUT, enableAppiumAnnotations, enableJavascriptAnnotations);27}28public AppiumFieldDecorator(AppiumDriver driver, int timeOutInSeconds, int sleepInMillis, boolean enableAppiumAnnotations, boolean enableJavascriptAnnotations, boolean enableFindBysForAndroidUIAutomator) {29 this(driver, timeOutInSeconds, sleepInMillis, enableAppiumAnnotations, enableJavascriptAnnotations);

Full Screen

Full Screen

ProxyFactory

Using AI Code Generation

copy

Full Screen

1import io.appium.java_client.pagefactory.utils.ProxyFactory;2import org.openqa.selenium.support.PageFactory;3import org.testng.annotations.Test;4public class ProxyFactoryTest {5 public void testProxyFactory() {6 SamplePage samplePage = new SamplePage();7 ProxyFactory proxyFactory = new ProxyFactory();8 SamplePage page = PageFactory.initElements(proxyFactory.setHandler(new AppiumFieldDecorator(new

Full Screen

Full Screen

ProxyFactory

Using AI Code Generation

copy

Full Screen

1ProxyFactory factory = new ProxyFactory(driver);2factory.setRootLocator(By.id("android:id/list"));3factory.addDecorator(new AppiumFieldDecorator(driver));4MyPageObject page = factory.create(MyPageObject.class);5PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());6PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());7PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());8PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());9PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());10PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());11PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());12PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());13PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());14PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());15PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());16PageFactory.initElements(new AppiumFieldDecorator(driver), new MyPageObject());

Full Screen

Full Screen

ProxyFactory

Using AI Code Generation

copy

Full Screen

1public class PageObjectClass {2 @FindBys({3 @FindBy(id = "id1"),4 @FindBy(id = "id2")5 })6 private MobileElement element;7 public PageObjectClass(AppiumDriver driver) {8 ProxyFactory factory = new ProxyFactory();9 factory.setProxyHandler(new AppiumFieldDecorator(driver));10 factory.setInterfaces(new Class[] { PageObjectClass.class });11 factory.setTarget(this);12 factory.create();13 }14}15class PageObjectClass {16 @FindBys(17 Array(18 new FindBy(id = "id1"),19 new FindBy(id = "id2")20 def this(driver: AppiumDriver) {21 this()22 factory.setProxyHandler(new AppiumFieldDecorator(driver))23 factory.setInterfaces(Array(classOf[PageObjectClass]))24 factory.setTarget(this)25 factory.create()26 }27}28class PageObjectClass {29 @FindBys([30 @FindBy(id = "id1"),31 @FindBy(id = "id2")32 def PageObjectClass(driver) {33 ProxyFactory factory = new ProxyFactory()34 factory.setProxyHandler(new AppiumFieldDecorator(driver))35 factory.setInterfaces([PageObjectClass])36 factory.setTarget(this)37 factory.create()38 }39}

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 methods 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