How to use LocatingListHandler method of com.qaprosoft.carina.core.foundation.webdriver.locator.internal.LocatingListHandler class

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

Source:ExtendedFieldDecorator.java Github

copy

Full Screen

...36import org.slf4j.LoggerFactory;37import com.qaprosoft.carina.core.foundation.webdriver.locator.ExtendedFindBy;38import com.qaprosoft.carina.core.foundation.webdriver.locator.LocalizedAnnotations;39import com.qaprosoft.carina.core.foundation.webdriver.locator.internal.AbstractUIObjectListHandler;40import com.qaprosoft.carina.core.foundation.webdriver.locator.internal.LocatingListHandler;41import com.qaprosoft.carina.core.gui.AbstractUIObject;42public class ExtendedFieldDecorator implements FieldDecorator {43 private static final Logger LOGGER = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());44 protected ElementLocatorFactory factory;45 private WebDriver webDriver;46 47 public ExtendedFieldDecorator(ElementLocatorFactory factory, WebDriver webDriver) {48 this.factory = factory;49 this.webDriver = webDriver;50 }51 public Object decorate(ClassLoader loader, Field field) {52 if ((!field.isAnnotationPresent(FindBy.class) && !field.isAnnotationPresent(ExtendedFindBy.class))53 /*54 * Enable field decorator logic only in case of55 * presence the FindBy/FindByCarina/FindByAI annotation in the56 * field57 */ ||58 !(ExtendedWebElement.class.isAssignableFrom(field.getType()) || AbstractUIObject.class.isAssignableFrom(field.getType())59 || isDecoratableList(field)) /*60 * also verify that it is ExtendedWebElement or derived from AbstractUIObject or DecoratableList61 */) {62 // returning null is ok in this method.63 return null;64 }65 ElementLocator locator;66 try {67 locator = factory.createLocator(field);68 } catch (Exception e) {69 LOGGER.error("Error while creating locator!", e);70 return null;71 }72 if (locator == null) {73 return null;74 }75 if (ExtendedWebElement.class.isAssignableFrom(field.getType())) {76 return proxyForLocator(loader, field, locator);77 }78 if (AbstractUIObject.class.isAssignableFrom(field.getType())) {79 return proxyForAbstractUIObject(loader, field, locator);80 } else if (List.class.isAssignableFrom(field.getType())) {81 Type listType = getListType(field);82 if (ExtendedWebElement.class.isAssignableFrom((Class<?>) listType)) {83 return proxyForListLocator(loader, field, locator);84 } else if (AbstractUIObject.class.isAssignableFrom((Class<?>) listType)) {85 return proxyForListUIObjects(loader, field, locator);86 } else {87 return null;88 }89 } else {90 return null;91 }92 }93 private boolean isDecoratableList(Field field) {94 if (!List.class.isAssignableFrom(field.getType())) {95 return false;96 }97 Type listType = getListType(field);98 if (listType == null) {99 return false;100 }101 try {102 if (!(ExtendedWebElement.class.equals(listType) || AbstractUIObject.class.isAssignableFrom((Class<?>) listType))) {103 return false;104 }105 } catch (ClassCastException e) {106 return false;107 }108 return true;109 }110 protected ExtendedWebElement proxyForLocator(ClassLoader loader, Field field, ElementLocator locator) {111 InvocationHandler handler = new LocatingElementHandler(locator);112 WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[] { WebElement.class, WrapsElement.class, Locatable.class },113 handler);114 /**115 * Questionable place - called ExtendedWebElement constructor with no initializing searchContext116 */117 return new ExtendedWebElement(proxy, field.getName(),118 field.isAnnotationPresent(FindBy.class) || field.isAnnotationPresent(ExtendedFindBy.class)? new LocalizedAnnotations(field).buildBy() : null);119 }120 @SuppressWarnings("unchecked")121 protected <T extends AbstractUIObject> T proxyForAbstractUIObject(ClassLoader loader, Field field,122 ElementLocator locator) {123 InvocationHandler handler = new LocatingElementHandler(locator);124 WebElement proxy = (WebElement) Proxy.newProxyInstance(loader, new Class[] { WebElement.class, WrapsElement.class, Locatable.class },125 handler);126 Class<? extends AbstractUIObject> clazz = (Class<? extends AbstractUIObject>) field.getType();127 T uiObject;128 try {129 uiObject = (T) clazz.getConstructor(WebDriver.class, SearchContext.class).newInstance(130 webDriver, proxy);131 } catch (NoSuchMethodException e) {132 throw new RuntimeException(133 "Implement appropriate AbstractUIObject constructor for auto-initialization!", e);134 } catch (Exception e) {135 throw new RuntimeException("Error creating UIObject!", e);136 }137 uiObject.setName(field.getName());138 uiObject.setRootElement(proxy);139 uiObject.setRootBy(getLocatorBy(locator));140 return uiObject;141 }142 @SuppressWarnings("unchecked")143 protected List<ExtendedWebElement> proxyForListLocator(ClassLoader loader, Field field, ElementLocator locator) {144 InvocationHandler handler = new LocatingListHandler(loader, locator, field);145 List<ExtendedWebElement> proxies = (List<ExtendedWebElement>) Proxy.newProxyInstance(loader, new Class[] { List.class }, handler);146 return proxies;147 }148 @SuppressWarnings("unchecked")149 protected <T extends AbstractUIObject> List<T> proxyForListUIObjects(ClassLoader loader, Field field,150 ElementLocator locator) {151 InvocationHandler handler = new AbstractUIObjectListHandler<T>((Class<?>) getListType(field), webDriver,152 locator, field.getName());153 List<T> proxies = (List<T>) Proxy.newProxyInstance(loader, new Class[] { List.class }, handler);154 return proxies;155 }156 private Type getListType(Field field) {157 // Type erasure in Java isn't complete. Attempt to discover the generic158 // type of the list....

Full Screen

Full Screen

Source:LocatingListHandler.java Github

copy

Full Screen

...28import org.openqa.selenium.internal.WrapsElement;29import org.openqa.selenium.support.pagefactory.ElementLocator;30import com.qaprosoft.carina.core.foundation.webdriver.decorator.ExtendedWebElement;31import com.qaprosoft.carina.core.foundation.webdriver.locator.LocalizedAnnotations;32public class LocatingListHandler implements InvocationHandler {33 private final ElementLocator locator;34 private String name;35 private By by;36 private final ClassLoader loader;37 public LocatingListHandler(ClassLoader loader, ElementLocator locator, Field field){38 this.loader = loader;39 this.locator = locator;40 this.name = field.getName();41 this.by = new LocalizedAnnotations(field).buildBy();42 }43 public Object invoke(Object object, Method method, Object[] objects) throws Throwable {44 // Hotfix for huge and expected regression in carina: we lost managed45 // time delays with lists manipulations46 // Temporary we are going to restore explicit waiter here with hardcoded47 // timeout before we find better solution48 // Pros: super fast regression issue which block UI execution49 // Cons: there is no way to manage timeouts in this places50// if (!waitUntil(ExpectedConditions.or(ExpectedConditions.presenceOfElementLocated(by),51// ExpectedConditions.visibilityOfElementLocated(by)))) {...

Full Screen

Full Screen

LocatingListHandler

Using AI Code Generation

copy

Full Screen

1public class 1 {2 public static void main(String[] args) {3 WebDriver driver = new FirefoxDriver();4 WebElement element = driver.findElement(By.name("q"));5 element.sendKeys("Cheese!");6 element.submit();7 System.out.println("Page title is: " + driver.getTitle());8 (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {9 public Boolean apply(WebDriver d) {10 return d.getTitle().toLowerCase().startsWith("cheese!");11 }12 });13 System.out.println("Page title is: " + driver.getTitle());14 driver.quit();15 }16}17public class 2 {18 public static void main(String[] args) {19 WebDriver driver = new FirefoxDriver();20 WebElement element = driver.findElement(By.name("q"));21 element.sendKeys("Cheese!");22 element.submit();23 System.out.println("Page

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

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

Most used method in LocatingListHandler

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful