How to use AbstractUIObjectListHandler class of com.qaprosoft.carina.core.foundation.webdriver.locator.internal package

Best Carina code snippet using com.qaprosoft.carina.core.foundation.webdriver.locator.internal.AbstractUIObjectListHandler

copy

Full Screen

...31import org.openqa.selenium.support.pagefactory.ElementLocatorFactory;32import org.openqa.selenium.support.pagefactory.FieldDecorator;33import org.openqa.selenium.support.pagefactory.internal.LocatingElementHandler;34import com.qaprosoft.carina.core.foundation.webdriver.locator.LocalizedAnnotations;35import com.qaprosoft.carina.core.foundation.webdriver.locator.internal.AbstractUIObjectListHandler;36import com.qaprosoft.carina.core.foundation.webdriver.locator.internal.LocatingElementListHandler;37import com.qaprosoft.carina.core.gui.AbstractUIObject;38public class ExtendedFieldDecorator implements FieldDecorator39{40 private Logger LOGGER = Logger.getLogger(ExtendedFieldDecorator.class);41 protected ElementLocatorFactory factory;42 private WebDriver webDriver;43 public ExtendedFieldDecorator(ElementLocatorFactory factory, WebDriver webDriver)44 {45 this.factory = factory;46 this.webDriver = webDriver;47 }48 public Object decorate(ClassLoader loader, Field field)49 {50 if (!field.isAnnotationPresent(FindBy.class) /​*Enable field decorator logic only in case of presence the FindBy annotation in the field*/​ ||51 !(ExtendedWebElement.class.isAssignableFrom(field.getType()) || AbstractUIObject.class.isAssignableFrom(field.getType()) || isDecoratableList(field)) /​*also verify that it is ExtendedWebElement or derived from AbstractUIObject or DecoratableList*/​)52 {53 /​/​ returning null is ok in this method.54 return null;55 }56 ElementLocator locator;57 try58 {59 locator = factory.createLocator(field);60 } catch (Exception e)61 {62 LOGGER.error(e.getMessage(), e);63 return null;64 }65 if (locator == null)66 {67 return null;68 }69 if (ExtendedWebElement.class.isAssignableFrom(field.getType()))70 {71 return proxyForLocator(loader, field, locator);72 }73 if (AbstractUIObject.class.isAssignableFrom(field.getType()))74 {75 return proxyForAbstractUIObject(loader, field, locator);76 }77 else if (List.class.isAssignableFrom(field.getType()))78 {79 Type listType = getListType(field);80 if (ExtendedWebElement.class.isAssignableFrom((Class<?>) listType))81 {82 return proxyForListLocator(loader, field, locator);83 }84 else if (AbstractUIObject.class.isAssignableFrom((Class<?>) listType))85 {86 return proxyForListUIObjects(loader, field, locator);87 }88 else89 {90 return null;91 }92 } else93 {94 return null;95 }96 }97 private boolean isDecoratableList(Field field)98 {99 if (!List.class.isAssignableFrom(field.getType()))100 {101 return false;102 }103 Type listType = getListType(field);104 if (listType == null)105 {106 return false;107 }108 try109 {110 if (!(ExtendedWebElement.class.equals(listType) || AbstractUIObject.class.isAssignableFrom((Class<?>) listType)))111 {112 return false;113 }114 } catch (ClassCastException e)115 {116 return false;117 }118 return true;119 }120 protected ExtendedWebElement proxyForLocator(ClassLoader loader, Field field, ElementLocator locator)121 {122 InvocationHandler handler = new LocatingElementHandler(locator);123 WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[]124 { WebElement.class, WrapsElement.class, Locatable.class }, handler);125 return new ExtendedWebElement(proxy, field.getName(), new LocalizedAnnotations(field).buildBy(), webDriver);126 }127 @SuppressWarnings("unchecked")128 protected <T extends AbstractUIObject> T proxyForAbstractUIObject(ClassLoader loader, Field field,129 ElementLocator locator)130 {131 InvocationHandler handler = new LocatingElementHandler(locator);132 WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[]133 { WebElement.class, WrapsElement.class, Locatable.class }, handler);134 Class<? extends AbstractUIObject> clazz = (Class<? extends AbstractUIObject>) field.getType();135 T uiObject;136 try137 {138 uiObject = (T) clazz.getConstructor(WebDriver.class, SearchContext.class).newInstance(139 webDriver, proxy);140 } catch (NoSuchMethodException e)141 {142 LOGGER.error("Implement appropriate AbstractUIObject constructor for auto-initialization: "143 + e.getMessage());144 throw new RuntimeException(145 "Implement appropriate AbstractUIObject constructor for auto-initialization: "146 + e.getMessage(), e);147 } catch (Exception e)148 {149 LOGGER.error("Error creating UIObject: " + e.getMessage());150 throw new RuntimeException("Error creating UIObject: " + e.getMessage(), e);151 }152 uiObject.setName(field.getName());153 uiObject.setRootElement(proxy);154 return uiObject;155 }156 @SuppressWarnings("unchecked")157 protected List<ExtendedWebElement> proxyForListLocator(ClassLoader loader, Field field, ElementLocator locator)158 {159 InvocationHandler handler = new LocatingElementListHandler(locator, field.getName(), new LocalizedAnnotations(field).buildBy(), webDriver);160 List<ExtendedWebElement> proxies = (List<ExtendedWebElement>) Proxy.newProxyInstance(loader, new Class[]161 { List.class }, handler);162 return proxies;163 }164 @SuppressWarnings("unchecked")165 protected <T extends AbstractUIObject> List<T> proxyForListUIObjects(ClassLoader loader, Field field,166 ElementLocator locator)167 {168 InvocationHandler handler = new AbstractUIObjectListHandler<T>((Class<?>) getListType(field), webDriver,169 locator, field.getName());170 List<T> proxies = (List<T>) Proxy.newProxyInstance(loader, new Class[]171 { List.class }, handler);172 return proxies;173 }174 private Type getListType(Field field)175 {176 /​/​ Type erasure in Java isn't complete. Attempt to discover the generic177 /​/​ type of the list.178 Type genericType = field.getGenericType();179 if (!(genericType instanceof ParameterizedType))180 {181 return null;182 }...

Full Screen

Full Screen
copy

Full Screen

...25import org.openqa.selenium.WebElement;26import org.openqa.selenium.support.pagefactory.ElementLocator;27import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedFieldDecorator;28import com.qaprosoft.carina.core.gui.AbstractUIObject;29public class AbstractUIObjectListHandler<T extends AbstractUIObject> implements InvocationHandler30{31 private Class<?> clazz;32 private WebDriver webDriver;33 private final ElementLocator locator;34 private String name;35 private Logger LOGGER = Logger.getLogger(ExtendedFieldDecorator.class);36 public AbstractUIObjectListHandler(Class<?> clazz, WebDriver webDriver, ElementLocator locator, String name)37 {38 this.clazz = clazz;39 this.webDriver = webDriver;40 this.locator = locator;41 this.name = name;42 }43 @SuppressWarnings("unchecked")44 public Object invoke(Object object, Method method, Object[] objects) throws Throwable45 {46 List<WebElement> elements = locator.findElements();47 List<T> uIObjects = new ArrayList<T>();48 int index = 0;49 if (elements != null)50 {...

Full Screen

Full Screen

Blogs

Check out the latest blogs from LambdaTest on this topic:

A Complete Guide To CSS Container Queries

In 2007, Steve Jobs launched the first iPhone, which revolutionized the world. But because of that, many businesses dealt with the problem of changing the layout of websites from desktop to mobile by delivering completely different mobile-compatible websites under the subdomain of ‘m’ (e.g., https://m.facebook.com). And we were all trying to figure out how to work in this new world of contending with mobile and desktop screen sizes.

Getting Started with SpecFlow Actions [SpecFlow Automation Tutorial]

With the rise of Agile, teams have been trying to minimize the gap between the stakeholders and the development team.

Top 17 Resources To Learn Test Automation

Lack of training is something that creates a major roadblock for a tester. Often, testers working in an organization are all of a sudden forced to learn a new framework or an automation tool whenever a new project demands it. You may be overwhelmed on how to learn test automation, where to start from and how to master test automation for web applications, and mobile applications on a new technology so soon.

Why Selenium WebDriver Should Be Your First Choice for Automation Testing

Developed in 2004 by Thoughtworks for internal usage, Selenium is a widely used tool for automated testing of web applications. Initially, Selenium IDE(Integrated Development Environment) was being used by multiple organizations and testers worldwide, benefits of automation testing with Selenium saved a lot of time and effort. The major downside of automation testing with Selenium IDE was that it would only work with Firefox. To resolve the issue, Selenium RC(Remote Control) was used which enabled Selenium to support automated cross browser testing.

A Detailed Guide To Xamarin Testing

Xamarin is an open-source framework that offers cross-platform application development using the C# programming language. It helps to simplify your overall development and management of cross-platform software applications.

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 Carina automation tests on LambdaTest cloud grid

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

Most used methods in AbstractUIObjectListHandler

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful