How to use isList method of org.fluentlenium.utils.CollectionUtils class

Best FluentLenium code snippet using org.fluentlenium.utils.CollectionUtils.isList

Source:InjectionAnnotations.java Github

copy

Full Screen

...3import static io.appium.java_client.remote.MobilePlatform.ANDROID;4import static io.appium.java_client.remote.MobilePlatform.IOS;5import static io.appium.java_client.remote.MobilePlatform.WINDOWS;6import static java.util.Optional.ofNullable;7import static org.fluentlenium.utils.CollectionUtils.isList;8import io.appium.java_client.pagefactory.DefaultElementByBuilder;9import org.fluentlenium.configuration.ConfigurationException;10import org.fluentlenium.core.label.FluentLabelProvider;11import org.fluentlenium.core.page.ClassAnnotations;12import org.fluentlenium.utils.ReflectionUtils;13import org.openqa.selenium.By;14import org.openqa.selenium.Capabilities;15import org.openqa.selenium.support.ByIdOrName;16import org.openqa.selenium.support.pagefactory.AbstractAnnotations;17import org.openqa.selenium.support.pagefactory.Annotations;18import java.lang.annotation.Annotation;19import java.lang.reflect.Field;20import java.util.Arrays;21/**22 * Inspired by {@link org.openqa.selenium.support.pagefactory.Annotations}, but also supports annotations defined on23 * return type class.24 */25public class InjectionAnnotations extends AbstractAnnotations implements FluentLabelProvider {26 private final ClassAnnotations classAnnotations;27 private final Annotations fieldAnnotations;28 private final LabelAnnotations labelFieldAnnotations;29 private final DefaultElementByBuilder defaultElementByBuilder;30 private final boolean mobileElement;31 /**32 * Creates a new injection annotations object33 *34 * @param field field to analyze35 * @param capabilities Selenium capabilities36 */37 public InjectionAnnotations(Field field, Capabilities capabilities) {38 classAnnotations = new ClassAnnotations(getEffectiveClass(field));39 fieldAnnotations = new Annotations(field);40 labelFieldAnnotations = new LabelAnnotations(field);41 String platform = getPlatform(capabilities);42 String automation = getAutomation(capabilities);43 defaultElementByBuilder = new DefaultElementByBuilder(platform, automation);44 if (isAnnotatedWithSupportedMobileBy(field)) {45 checkCapabilities(platform, automation);46 defaultElementByBuilder.setAnnotated(field);47 mobileElement = true;48 } else {49 mobileElement = false;50 }51 }52 private void checkCapabilities(String platform, String automation) {53 boolean correctConfiguration = isAndroid(platform) || isIos(platform, automation) || isWindows(platform);54 if (!correctConfiguration) {55 throw new ConfigurationException("You have annotated elements with Appium @FindBys"56 + " but capabilities are incomplete. Please use one of these configurations:\n"57 + "platformName:Windows\n"58 + "plaformName:Android\n"59 + "plaformName:iOS, automationName:XCUITest");60 }61 }62 private boolean isWindows(String platform) {63 return WINDOWS.equalsIgnoreCase(platform);64 }65 private boolean isIos(String platform, String automation) {66 return IOS.equalsIgnoreCase(platform) && IOS_XCUI_TEST.equalsIgnoreCase(automation);67 }68 private boolean isAndroid(String platform) {69 return ANDROID.equalsIgnoreCase(platform);70 }71 private String getAutomation(Capabilities capabilities) {72 return ofNullable(capabilities)73 .map(capability -> capability.getCapability("automationName"))74 .map(String::valueOf)75 .orElse(null);76 }77 private String getPlatform(Capabilities capabilities) {78 if (capabilities == null) {79 return null;80 }81 Object platformName = ofNullable(capabilities.getCapability("platformName"))82 .orElseGet(() -> capabilities.getCapability("platform"));83 return ofNullable(platformName).map(String::valueOf).orElse(null);84 }85 private boolean isAnnotatedWithSupportedMobileBy(Field field) {86 Annotation[] annotations = field.getAnnotations();87 return Arrays.stream(annotations)88 .anyMatch(SupportedAppiumAnnotations::isSupported);89 }90 @Override91 public By buildBy() {92 if (mobileElement) {93 return defaultElementByBuilder.buildBy();94 }95 By fieldBy = fieldAnnotations.buildBy();96 By classBy = classAnnotations.buildBy();97 if (classBy != null && fieldBy instanceof ByIdOrName) {98 return classBy;99 }100 return fieldBy;101 }102 @Override103 public boolean isLookupCached() {104 return classAnnotations.isLookupCached() || fieldAnnotations.isLookupCached();105 }106 @Override107 public String getLabel() {108 return labelFieldAnnotations.getLabel();109 }110 @Override111 public String[] getLabelHints() {112 return labelFieldAnnotations.getLabelHints();113 }114 private static Class<?> getEffectiveClass(Field field) {115 if (isList(field)) {116 Class<?> effectiveClass = ReflectionUtils.getFirstGenericType(field);117 if (effectiveClass != null) {118 return effectiveClass;119 }120 }121 return field.getType();122 }123}...

Full Screen

Full Screen

Source:FluentElementInjectionSupportValidator.java Github

copy

Full Screen

1package org.fluentlenium.core.inject;2import static java.util.Objects.requireNonNull;3import static org.fluentlenium.core.inject.InjectionAnnotationSupport.isNoInject;4import static org.fluentlenium.utils.CollectionUtils.isList;5import org.fluentlenium.core.components.ComponentsManager;6import org.fluentlenium.core.domain.FluentWebElement;7import org.fluentlenium.utils.ReflectionUtils;8import org.openqa.selenium.WebElement;9import java.lang.reflect.Field;10import java.lang.reflect.Modifier;11import java.util.List;12import java.util.function.Predicate;13/**14 * Provides method for validating whether the injection of a field into a container is supported,15 * and methods for validating if fields has certain types.16 */17final class FluentElementInjectionSupportValidator {18 private final ComponentsManager componentsManager;19 FluentElementInjectionSupportValidator(ComponentsManager componentsManager) {20 this.componentsManager = requireNonNull(componentsManager);21 }22 /**23 * Returns whether injection of the argument field is supported into the argument container.24 *25 * @param container the container object to inject into26 * @param field the field to inject27 * @return true if injection is supported, false otherwise28 */29 boolean isSupported(Object container, Field field) {30 return isFieldExist(container, field)31 && !isNoInject(field)32 && !Modifier.isFinal(field.getModifiers())33 && (isListOfFluentWebElement(field)34 || isListOfComponent(field)35 || isComponent(field)36 || isComponentList(field)37 || isWebElement(field)38 || isListOfWebElement(field));39 }40 private static boolean isFieldExist(Object container, Field field) {41 try {42 return ReflectionUtils.get(field, container) == null;43 } catch (IllegalAccessException e) {44 throw new FluentInjectException("Can't retrieve default value of field", e);45 }46 }47 /**48 * Checks whether the argument field is a list of components e.g. {@link FluentWebElement} or any other custom component:49 * {@code List<FluentWebElement> elements} or for a custom component {@code Component} it would be50 * {@code List<Component> components;}.51 *52 * @param field the field to check the type of53 * @return true if field is a list of components, false otherwise54 */55 boolean isListOfComponent(Field field) {56 //Don't replace the predicate with a method reference57 return isFieldListOf(field, genericType -> componentsManager.isComponentClass(genericType));58 }59 /**60 * Checks whether the argument field is a component e.g. {@link FluentWebElement} or any other custom component.61 *62 * @param field the field to check the type of63 * @return true if field is a component, false otherwise64 */65 boolean isComponent(Field field) {66 return componentsManager.isComponentClass(field.getType());67 }68 /**69 * Checks whether the argument field is a type that extends {@link List} and its generic type is a component70 * e.g. {@link FluentWebElement} or any other custom component.71 *72 * @param field the field to check the type of73 * @return true if field is a list of components, false otherwise74 */75 boolean isComponentList(Field field) {76 if (isList(field)) {77 boolean componentListClass = componentsManager.isComponentListClass((Class<? extends List<?>>) field.getType());78 if (componentListClass) {79 Class<?> genericType = ReflectionUtils.getFirstGenericType(field);80 return genericType != null && componentsManager.isComponentClass(genericType);81 }82 }83 return false;84 }85 /**86 * Checks whether the argument field is a list of {@link FluentWebElement}s: {@code List<FluentWebElement> elements;}87 *88 * @param field the field to check the type of89 * @return true if field is a list of FluentWebElements, false otherwise90 */91 static boolean isListOfFluentWebElement(Field field) {92 return isFieldListOf(field, FluentWebElement.class::isAssignableFrom);93 }94 /**95 * Checks whether the argument field is a {@link WebElement}.96 *97 * @param field the field to check the type of98 * @return true if field is WebElement, false otherwise99 */100 static boolean isWebElement(Field field) {101 return WebElement.class.isAssignableFrom(field.getType());102 }103 /**104 * Checks whether the argument field is a list of {@link WebElement}s: {@code List<WebElement> elements;}105 *106 * @param field the field to check the type of107 * @return true if field is a list of WebElements, false otherwise108 */109 static boolean isListOfWebElement(Field field) {110 return isFieldListOf(field, WebElement.class::isAssignableFrom);111 }112 private static boolean isFieldListOf(Field field, Predicate<Class<?>> typePredicate) {113 if (isList(field)) {114 Class<?> genericType = ReflectionUtils.getFirstGenericType(field);115 return genericType != null && typePredicate.test(genericType);116 }117 return false;118 }119}...

Full Screen

Full Screen

Source:CollectionUtils.java Github

copy

Full Screen

...14 *15 * @param field the field to check the type of16 * @return true if the field is a List, false otherwise17 */18 public static boolean isList(Field field) {19 return List.class.isAssignableFrom(field.getType());20 }21 /**22 * Returns whether a collection is null or empty.23 *24 * @param collection the collection to check25 * @return true if the collection is either null or empty, false otherwise26 */27 public static boolean isEmpty(Collection<?> collection) {28 return collection == null || collection.isEmpty();29 }30}...

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.domain.FluentWebElement;2import org.fluentlenium.utils.CollectionUtils;3import org.openqa.selenium.By;4import org.openqa.selenium.WebElement;5import org.openqa.selenium.support.FindBy;6import org.testng.annotations.Test;7import java.util.List;8public class isList extends BaseTest {9 @FindBy(css = "div")10 private List<WebElement> divs;11 @FindBy(css = "div")12 private List<FluentWebElement> fluentDivs;13 public void testIsList() {14 System.out.println(CollectionUtils.isList(divs));15 System.out.println(CollectionUtils.isList(fluentDivs));16 }17}18import org.fluentlenium.core.domain.FluentWebElement;19import org.openqa.selenium.By;20import org.openqa.selenium.WebElement;21import org.openqa.selenium.support.FindBy;22import org.testng.annotations.Test;23import java.util.List;24public class isList extends BaseTest {25 @FindBy(css = "div")26 private List<WebElement> divs;27 @FindBy(css = "div")28 private List<FluentWebElement> fluentDivs;29 public void testIsList() {30 System.out.println(divs instanceof List);31 System.out.println(fluentDivs instanceof List);32 }33}34import org.fluentlenium.core.domain.FluentWebElement;35import org.openqa.selenium.By;36import org.openqa.selenium.WebElement;37import org.openqa.selenium.support.FindBy;38import org.testng.annotations.Test;39import java.util.List;40public class isList extends BaseTest {41 @FindBy(css = "div")42 private List<WebElement> divs;43 @FindBy(css = "div")44 private List<FluentWebElement> fluentDivs;45 public void testIsList() {46 System.out.println(divs instanceof List);47 System.out.println(fluentDivs instanceof List);48 }49}50import org.fluentlenium.core.domain.FluentWebElement;51import org.openqa.selenium.By;52import org.openqa.selenium.WebElement;53import org.openqa.selenium.support.FindBy;54import org.testng.annotations.Test;55import java.util.List;56public class isList extends BaseTest {57 @FindBy(css = "div")58 private List<WebElement> divs;

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.utils.CollectionUtils;2import java.util.ArrayList;3import java.util.List;4public class 4 {5 public static void main(String[] args) {6 List<String> list = new ArrayList();7 list.add("one");8 list.add("two");9 list.add("three");10 list.add("four");11 System.out.println(CollectionUtils.isList(list));12 }13}

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1package com.fluentlenium.tutorial;2import org.fluentlenium.core.FluentPage;3import org.openqa.selenium.WebDriver;4public class Page4 extends FluentPage {5 public String getUrl() {6 }7 public void isAt() {8 assert title().equals("List");9 }10 public void selectFirst() {11 if (CollectionUtils.isList(find("#list").first().find("option"))) {12 find("#list").first().find("option").first().click();13 }14 }15}16package com.fluentlenium.tutorial;17import org.fluentlenium.core.FluentPage;18import org.openqa.selenium.WebDriver;19public class Page5 extends FluentPage {20 public String getUrl() {21 }22 public void isAt() {23 assert title().equals("List");24 }25 public void selectFirst() {26 if (CollectionUtils.isList(find("#list").first().find("option"))) {27 find("#list").first().find("option").first().click();28 }29 }30}31package com.fluentlenium.tutorial;32import org.fluentlenium.core.FluentPage;33import org.openqa.selenium.WebDriver;34public class Page6 extends FluentPage {35 public String getUrl() {36 }37 public void isAt() {38 assert title().equals("List");39 }40 public void selectFirst() {41 if (CollectionUtils.isList(find("#list").first().find("option"))) {42 find("#list").first().find("option").first().click();43 }44 }45}46package com.fluentlenium.tutorial;47import org.fluentlenium.core.FluentPage;48import org.openqa.selenium.WebDriver;49public class Page7 extends FluentPage {50 public String getUrl() {

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.utils.CollectionUtils;2import java.util.ArrayList;3import java.util.List;4public class 4 {5 public static void main(String[] args) {6 List<String> list = new ArrayList<>();7 System.out.println(CollectionUtils.isList(list));8 }9}

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.utils.CollectionUtils;2import java.util.ArrayList;3import java.util.Collection;4import java.util.List;5public class IsList {6 public static void main(String[] args) {7 List<String> list = new ArrayList<>();8 list.add("element 1");9 list.add("element 2");10 list.add("element 3");11 list.add("element 4");12 list.add("element 5");13 Collection<String> collection = list;14 System.out.println(CollectionUtils.isList(collection));15 }16}

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.core.domain.FluentList;2import org.fluentlenium.utils.CollectionUtils;3import org.junit.Test;4import org.openqa.selenium.By;5import org.openqa.selenium.WebElement;6import java.util.List;7public class 4 extends FluentTest {8 public void test() {9 List<WebElement> searchResults = find(By.cssSelector(".g")).getElements();10 if (CollectionUtils.isList(searchResults)) {11 System.out.println("Search results found");12 } else {13 System.out.println("No search results found");14 }15 }16}17import org.fluentlenium.core.domain.FluentList;18import org.fluentlenium.utils.CollectionUtils;19import org.junit.Test;20import org.openqa.selenium.By;21import org.openqa.selenium.WebElement;22import java.util.List;23public class 5 extends FluentTest {24 public void test() {25 List<WebElement> searchResults = find(By.cssSelector(".g")).getElements();26 if (CollectionUtils.isList(searchResults)) {27 System.out.println("Search results found");28 } else {29 System.out.println("No search results found");30 }31 }32}33import org.fluentlenium.core.domain.FluentList;34import org.fluentlenium.utils.CollectionUtils;35import org.junit.Test;36import org.openqa.selenium.By;37import org.openqa.selenium.WebElement;38import java.util.List;39public class 6 extends FluentTest {40 public void test() {41 List<WebElement> searchResults = find(By.cssSelector(".g")).getElements();42 if (CollectionUtils.isList(searchResults)) {43 System.out.println("Search results found");44 } else {45 System.out.println("No search results found");46 }47 }48}

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.utils.CollectionUtils;2import java.util.ArrayList;3import java.util.Collection;4import java.util.List;5import java.util.Set;6import java.util.HashSet;7public class ListOrNot {8 public static void main(String[] args) {9 CollectionUtils collectionUtils = new CollectionUtils();10 List<String> list = new ArrayList<String>();11 list.add("test1");12 list.add("test2");13 list.add("test3");14 list.add("test4");15 list.add("test5");16 System.out.println("Is list a list? " + collectionUtils.isList(list));17 Set<String> set = new HashSet<String>();18 set.add("test1");19 set.add("test2");20 set.add("test3");21 set.add("test4");22 set.add("test5");

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1import org.fluentlenium.utils.CollectionUtils;2import java.util.ArrayList;3import java.util.Collection;4import java.util.List;5public class CollectionUtilsIsListExample {6 public static void main(String[] args) {7 List<Integer> list = new ArrayList<Integer>();8 list.add(1);9 list.add(2);10 list.add(3);11 boolean isList = CollectionUtils.isList(list);12 System.out.println("Is list? " + isList);13 Collection<Integer> collection = new ArrayList<Integer>();14 collection.add(1);15 collection.add(2);16 collection.add(3);

Full Screen

Full Screen

isList

Using AI Code Generation

copy

Full Screen

1public class isList {2 public static void main(String[] args) {3 List list = new ArrayList();4 list.add("a");5 list.add("b");6 list.add("c");7 System.out.println("Is list: " + CollectionUtils.isList(list));8 }9}

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

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

Most used method in CollectionUtils

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful