Best io.appium code snippet using io.appium.java_client.pagefactory.bys.ContentMappedBy
DefaultElementByBuilder.java
Source:DefaultElementByBuilder.java  
...28import io.appium.java_client.pagefactory.iOSFindAll;29import io.appium.java_client.pagefactory.iOSFindBy;30import io.appium.java_client.pagefactory.iOSFindBys;31import io.appium.java_client.pagefactory.iOSXCUITFindBy;32import io.appium.java_client.pagefactory.bys.ContentMappedBy;33import io.appium.java_client.pagefactory.bys.ContentType;34import io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder;35import io.appium.java_client.pagefactory.bys.builder.HowToUseSelectors;36import org.openqa.selenium.By;37import org.openqa.selenium.support.ByIdOrName;38import org.openqa.selenium.support.CacheLookup;39import org.openqa.selenium.support.FindAll;40import org.openqa.selenium.support.FindBy;41import org.openqa.selenium.support.FindBys;4243import java.lang.annotation.Annotation;44import java.lang.reflect.AnnotatedElement;45import java.lang.reflect.Field;46import java.util.HashMap;47import java.util.Map;48import java.util.Optional;4950class DefaultElementByBuilder extends AppiumByBuilder {5152    protected DefaultElementByBuilder(String platform, String automation) {53        super(platform, automation);54    }5556    private static void checkDisallowedAnnotationPairs(Annotation a1, Annotation a2)57        throws IllegalArgumentException {58        if (a1 != null && a2 != null) {59            throw new IllegalArgumentException(60                "If you use a '@" + a1.getClass().getSimpleName() + "' annotation, "61                    + "you must not also use a '@" + a2.getClass().getSimpleName()62                    + "' annotation");63        }64    }6566    private static By buildMobileBy(LocatorGroupStrategy locatorGroupStrategy, Annotation[] annotations) {67        if (annotations.length == 1) {68            return createBy(new Annotation[] {annotations[0]}, HowToUseSelectors.USE_ONE);69        } else {70            LocatorGroupStrategy strategy = Optional.ofNullable(locatorGroupStrategy)71                    .orElse(LocatorGroupStrategy.CHAIN);72            if (strategy.equals(LocatorGroupStrategy.ALL_POSSIBLE)) {73                return createBy(annotations, HowToUseSelectors.USE_ANY);74            }75            return createBy(annotations, HowToUseSelectors.BUILD_CHAINED);76        }77    }7879    @Override protected void assertValidAnnotations() {80        AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();81        AndroidFindBy androidBy = annotatedElement.getAnnotation(AndroidFindBy.class);82        AndroidFindBys androidBys = annotatedElement.getAnnotation(AndroidFindBys.class);83        checkDisallowedAnnotationPairs(androidBy, androidBys);84        AndroidFindAll androidFindAll = annotatedElement.getAnnotation(AndroidFindAll.class);85        checkDisallowedAnnotationPairs(androidBy, androidFindAll);86        checkDisallowedAnnotationPairs(androidBys, androidFindAll);8788        SelendroidFindBy selendroidBy = annotatedElement.getAnnotation(SelendroidFindBy.class);89        SelendroidFindBys selendroidBys = annotatedElement.getAnnotation(SelendroidFindBys.class);90        checkDisallowedAnnotationPairs(selendroidBy, selendroidBys);91        SelendroidFindAll selendroidFindAll =92            annotatedElement.getAnnotation(SelendroidFindAll.class);93        checkDisallowedAnnotationPairs(selendroidBy, selendroidFindAll);94        checkDisallowedAnnotationPairs(selendroidBys, selendroidFindAll);9596        iOSFindBy iOSBy = annotatedElement.getAnnotation(iOSFindBy.class);97        iOSFindBys iOSBys = annotatedElement.getAnnotation(iOSFindBys.class);98        checkDisallowedAnnotationPairs(iOSBy, iOSBys);99        iOSFindAll iOSFindAll = annotatedElement.getAnnotation(iOSFindAll.class);100        checkDisallowedAnnotationPairs(iOSBy, iOSFindAll);101        checkDisallowedAnnotationPairs(iOSBys, iOSFindAll);102103        FindBy findBy = annotatedElement.getAnnotation(FindBy.class);104        FindBys findBys = annotatedElement.getAnnotation(FindBys.class);105        checkDisallowedAnnotationPairs(findBy, findBys);106        FindAll findAll = annotatedElement.getAnnotation(FindAll.class);107        checkDisallowedAnnotationPairs(findBy, findAll);108        checkDisallowedAnnotationPairs(findBys, findAll);109    }110111    @Override protected By buildDefaultBy() {112        AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();113        By defaultBy = null;114        FindBy findBy = annotatedElement.getAnnotation(FindBy.class);115        if (findBy != null) {116            defaultBy = super.buildByFromFindBy(findBy);117        }118119        if (defaultBy == null) {120            FindBys findBys = annotatedElement.getAnnotation(FindBys.class);121            if (findBys != null) {122                defaultBy = super.buildByFromFindBys(findBys);123            }124        }125126        if (defaultBy == null) {127            FindAll findAll = annotatedElement.getAnnotation(FindAll.class);128            if (findAll != null) {129                defaultBy = super.buildBysFromFindByOneOf(findAll);130            }131        }132        return defaultBy;133    }134135    @Override protected By buildMobileNativeBy() {136        AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();137        HowToUseLocators howToUseLocators = annotatedElement.getAnnotation(HowToUseLocators.class);138139        if (isSelendroidAutomation()) {140            SelendroidFindBy[] selendroidFindByArray =141                annotatedElement.getAnnotationsByType(SelendroidFindBy.class);142            //should be kept for some time143            SelendroidFindBys selendroidFindBys =144                annotatedElement.getAnnotation(SelendroidFindBys.class);145            SelendroidFindAll selendroidFindByAll =146                annotatedElement.getAnnotation(SelendroidFindAll.class);147148            if (selendroidFindByArray != null && selendroidFindByArray.length == 1) {149                return createBy(new Annotation[] {selendroidFindByArray[0]}, HowToUseSelectors.USE_ONE);150            }151152            if (selendroidFindBys != null) {153                return createBy(selendroidFindBys.value(), HowToUseSelectors.BUILD_CHAINED);154            }155156            if (selendroidFindByAll != null) {157                return createBy(selendroidFindByAll.value(), HowToUseSelectors.USE_ANY);158            }159            ///////////////////////////////////////160            //code that supposed to be supported161            if (selendroidFindByArray != null && selendroidFindByArray.length > 0) {162                return buildMobileBy(howToUseLocators != null ? howToUseLocators.selendroidAutomation() : null,163                        selendroidFindByArray);164            }165        }166167        if (isAndroid()) {168            AndroidFindBy[] androidFindByArray = annotatedElement.getAnnotationsByType(AndroidFindBy.class);169            //should be kept for some time170            AndroidFindBys androidFindBys = annotatedElement.getAnnotation(AndroidFindBys.class);171            AndroidFindAll androidFindAll = annotatedElement.getAnnotation(AndroidFindAll.class);172173            if (androidFindByArray != null && androidFindByArray.length == 1) {174                return createBy(new Annotation[] {androidFindByArray[0]}, HowToUseSelectors.USE_ONE);175            }176177            if (androidFindBys != null) {178                return createBy(androidFindBys.value(), HowToUseSelectors.BUILD_CHAINED);179            }180181            if (androidFindAll != null) {182                return createBy(androidFindAll.value(), HowToUseSelectors.USE_ANY);183            }184            ///////////////////////////////////////185            //code that supposed to be supported186            if (androidFindByArray != null && androidFindByArray.length > 0) {187                return buildMobileBy(howToUseLocators != null ? howToUseLocators.androidAutomation() : null,188                        androidFindByArray);189            }190        }191192        if (isIOSXcuit()) {193            iOSXCUITFindBy[] xCuitFindByArray = annotatedElement.getAnnotationsByType(iOSXCUITFindBy.class);194            if (xCuitFindByArray != null && xCuitFindByArray.length > 0) {195                return buildMobileBy(howToUseLocators != null ? howToUseLocators.iOSXCUITAutomation() : null,196                        xCuitFindByArray);197            }198        }199200        if (isIOS()) {201            iOSFindBy[] iOSFindByArray = annotatedElement.getAnnotationsByType(iOSFindBy.class);202            //should be kept for some time203            iOSFindBys iOSFindBys = annotatedElement.getAnnotation(iOSFindBys.class);204            iOSFindAll iOSFindAll = annotatedElement.getAnnotation(iOSFindAll.class);205206            if (iOSFindByArray != null && iOSFindByArray.length == 1) {207                return createBy(new Annotation[] {iOSFindByArray[0]}, HowToUseSelectors.USE_ONE);208            }209210            if (iOSFindBys != null) {211                return createBy(iOSFindBys.value(), HowToUseSelectors.BUILD_CHAINED);212            }213214            if (iOSFindAll != null) {215                return createBy(iOSFindAll.value(), HowToUseSelectors.USE_ANY);216            }217            ///////////////////////////////////////218            //code that supposed to be supported219            if (iOSFindByArray != null && iOSFindByArray.length > 0) {220                return buildMobileBy(howToUseLocators != null ? howToUseLocators.iOSAutomation() : null,221                        iOSFindByArray);222            }223        }224225        if (isWindows()) {226            WindowsFindBy[] windowsFindByArray = annotatedElement.getAnnotationsByType(WindowsFindBy.class);227            if (windowsFindByArray != null && windowsFindByArray.length > 0) {228                return buildMobileBy(howToUseLocators != null ? howToUseLocators.windowsAutomation() : null,229                        windowsFindByArray);230            }231        }232233        return null;234    }235236    @Override public boolean isLookupCached() {237        AnnotatedElement annotatedElement = annotatedElementContainer.getAnnotated();238        return (annotatedElement.getAnnotation(CacheLookup.class) != null);239    }240241    private By returnMappedBy(By byDefault, By nativeAppBy) {242        Map<ContentType, By> contentMap = new HashMap<>();243        contentMap.put(ContentType.HTML_OR_DEFAULT, byDefault);244        contentMap.put(ContentType.NATIVE_MOBILE_SPECIFIC, nativeAppBy);245        return new ContentMappedBy(contentMap);246    }247248    @Override public By buildBy() {249        assertValidAnnotations();250251        By defaultBy = buildDefaultBy();252        By mobileNativeBy = buildMobileNativeBy();253254        String idOrName = ((Field) annotatedElementContainer.getAnnotated()).getName();255256        if (defaultBy == null && mobileNativeBy == null) {257            defaultBy =258                new ByIdOrName(((Field) annotatedElementContainer.getAnnotated()).getName());259            mobileNativeBy = new By.ById(idOrName);
...FormattedElementLocator.java
Source:FormattedElementLocator.java  
1package com.automation.web.pageobjects.factory;2import io.appium.java_client.pagefactory.bys.ContentMappedBy;3import io.appium.java_client.pagefactory.bys.ContentType;4import io.appium.java_client.pagefactory.locator.CacheableLocator;5import java.lang.reflect.Constructor;6import java.lang.reflect.Field;7import java.lang.reflect.InvocationTargetException;8import java.lang.reflect.Modifier;9import java.util.ArrayList;10import java.util.Arrays;11import java.util.EnumMap;12import java.util.IllegalFormatException;13import java.util.LinkedList;14import java.util.List;15import java.util.Map;16import java.util.function.Function;17import java.util.stream.Collectors;18import org.openqa.selenium.By;19import org.openqa.selenium.SearchContext;20import org.openqa.selenium.WebElement;21import org.openqa.selenium.support.pagefactory.ByChained;22import org.openqa.selenium.support.pagefactory.ElementLocator;23/**24 * Element locator that formats its `formatArg` using the By strategy as a format string, e.g. a25 * locator with strategy `By.css("item%s")` and `1` passed as the format argument will be formatted26 * into a locator with strategy `By.css("item1")`.27 *28 * This allows for dynamic element lookup.29 */30public class FormattedElementLocator implements CacheableLocator {31    protected final SearchContext searchContext;32    protected final boolean shouldCache;33    protected final By by;34    protected WebElement cachedElement;35    protected List<WebElement> cachedElementList;36    public FormattedElementLocator(ElementLocator locator, Object formatArg) {37        Map<String, Field> fields = Arrays38                .stream(locator.getClass().getDeclaredFields())39                .collect(Collectors.toMap(Field::getName, Function.identity()));40        try {41            Field byField = fields.get("by");42            byField.setAccessible(true);43            By by = (By) byField.get(locator);44            this.by = formatBy(by, formatArg);45            Field searchContextField = fields.get("searchContext");46            searchContextField.setAccessible(true);47            this.searchContext = (SearchContext) searchContextField.get(locator);48            Field shouldCacheField = fields.get("shouldCache");49            shouldCacheField.setAccessible(true);50            this.shouldCache = (boolean) shouldCacheField.get(locator);51        } catch (IllegalAccessException e) {52            throw new FindByFormattingException(e);53        }54    }55    protected By formatBy(By originalBy, Object formatArg) throws IllegalAccessException {56        if (ByChained.class.isAssignableFrom(originalBy.getClass())) {57            return formatChainedBy((ByChained) originalBy, formatArg);58        } else if (ContentMappedBy.class.isAssignableFrom(originalBy.getClass())) {59            return formatMappedBy((ContentMappedBy) originalBy, formatArg);60        } else {61            return formatSimpleBy(originalBy, formatArg);62        }63    }64    @SuppressWarnings("unchecked")65    protected ContentMappedBy formatMappedBy(ContentMappedBy originalBy, Object formatArg) {66        Map<String, Field> fields = Arrays67                .stream(originalBy.getClass().getDeclaredFields())68                .collect(Collectors.toMap(Field::getName, Function.identity()));69        try {70            Field mapField = fields.get("map");71            mapField.setAccessible(true);72            Map<ContentType, By> originalMap = (Map<ContentType, By>) mapField.get(originalBy);73            Field currentContentField = fields.get("currentContent");74            currentContentField.setAccessible(true);75            ContentType originalCurrentContent = (ContentType) currentContentField.get(originalBy);76            By defaultBy = formatBy(originalMap.get(ContentType.HTML_OR_DEFAULT), formatArg);77            By mobileBy = formatBy(originalMap.get(ContentType.NATIVE_MOBILE_SPECIFIC), formatArg);78            Map<ContentType, By> map = new EnumMap<>(ContentType.class);79            map.put(ContentType.HTML_OR_DEFAULT, defaultBy);80            map.put(ContentType.NATIVE_MOBILE_SPECIFIC, mobileBy);81            return (ContentMappedBy) new ContentMappedBy(map).useContent(originalCurrentContent);82        } catch (IllegalAccessException e) {83            throw new FindByFormattingException(e);84        }85    }86    protected ByChained formatChainedBy(ByChained originalBy, Object formatArg)87            throws IllegalAccessException {88        Field[] fields = originalBy.getClass().getDeclaredFields();89        Field bysField = Arrays.stream(fields)90                .filter(field -> field.getName().equals("bys"))91                .findFirst().orElseThrow(() -> new RuntimeException(""));92        bysField.setAccessible(true);93        By[] originalBys = (By[]) bysField.get(originalBy);94        By[] bys = Arrays.stream(originalBys)95                .map(by -> formatSimpleBy(by, formatArg))...AppiumElementLocator.java
Source:AppiumElementLocator.java  
...18import static io.appium.java_client.pagefactory.ThrowableUtil.isInvalidSelectorRootCause;19import static io.appium.java_client.pagefactory.ThrowableUtil.isStaleElementReferenceException;20import static io.appium.java_client.pagefactory.utils.WebDriverUnpackUtility.getCurrentContentType;21import static java.lang.String.format;22import io.appium.java_client.pagefactory.bys.ContentMappedBy;23import io.appium.java_client.pagefactory.locator.CacheableLocator;24import org.openqa.selenium.By;25import org.openqa.selenium.NoSuchElementException;26import org.openqa.selenium.SearchContext;27import org.openqa.selenium.StaleElementReferenceException;28import org.openqa.selenium.TimeoutException;29import org.openqa.selenium.WebDriverException;30import org.openqa.selenium.WebElement;31import org.openqa.selenium.support.ui.FluentWait;32import java.time.Duration;33import java.util.ArrayList;34import java.util.List;35import java.util.function.Function;36import java.util.function.Supplier;37class AppiumElementLocator implements CacheableLocator {38    private static final String exceptionMessageIfElementNotFound = "Can't locate an element by this strategy: %s";39    private final boolean shouldCache;40    private final By by;41    private final Duration duration;42    private final SearchContext searchContext;43    private WebElement cachedElement;44    private List<WebElement> cachedElementList;45    /**46     * Creates a new mobile element locator. It instantiates {@link WebElement}47     * using @AndroidFindBy (-s), @iOSFindBy (-s) and @FindBy (-s) annotation48     * sets49     *50     * @param searchContext     The context to use when finding the element51     * @param by                a By locator strategy52     * @param shouldCache       is the flag that signalizes that elements which53     *                          are found once should be cached54     * @param duration          timeout parameter for the element to be found55     */56    public AppiumElementLocator(SearchContext searchContext, By by, boolean shouldCache,57                                Duration duration) {58        this.searchContext = searchContext;59        this.shouldCache = shouldCache;60        this.duration = duration;61        this.by = by;62    }63    /**64     * This methods makes sets some settings of the {@link By} according to65     * the given instance of {@link SearchContext}. If there is some {@link ContentMappedBy}66     * then it is switched to the searching for some html or native mobile element.67     * Otherwise nothing happens there.68     *69     * @param currentBy is some locator strategy70     * @param currentContent is an instance of some subclass of the {@link SearchContext}.71     * @return the corrected {@link By} for the further searching72     */73    private static By getBy(By currentBy, SearchContext currentContent) {74        if (!ContentMappedBy.class.isAssignableFrom(currentBy.getClass())) {75            return currentBy;76        }77        return ContentMappedBy.class.cast(currentBy)78                .useContent(getCurrentContentType(currentContent));79    }80    private <T> T waitFor(Supplier<T> supplier) {81        WaitingFunction<T> function = new WaitingFunction<>();82        try {83            FluentWait<Supplier<T>> wait = new FluentWait<>(supplier)84                    .ignoring(NoSuchElementException.class);85            wait.withTimeout(duration);86            return wait.until(function);87        } catch (TimeoutException e) {88            if (function.foundStaleElementReferenceException != null) {89                throw StaleElementReferenceException90                        .class.cast(function.foundStaleElementReferenceException);91            }...InjectionAnnotationsTest.java
Source:InjectionAnnotationsTest.java  
1package org.fluentlenium.core.inject;2import io.appium.java_client.AppiumBy;3import io.appium.java_client.MobileBy;4import io.appium.java_client.pagefactory.*;5import io.appium.java_client.pagefactory.bys.ContentMappedBy;6import io.appium.java_client.remote.MobileCapabilityType;7import org.fluentlenium.configuration.ConfigurationException;8import org.fluentlenium.core.domain.FluentWebElement;9import org.junit.Ignore;10import org.junit.Test;11import org.openqa.selenium.By;12import org.openqa.selenium.Capabilities;13import org.openqa.selenium.remote.CapabilityType;14import org.openqa.selenium.remote.DesiredCapabilities;15import org.openqa.selenium.support.FindBy;16import org.openqa.selenium.support.pagefactory.ByChained;17import java.lang.reflect.Field;18import static org.assertj.core.api.Assertions.assertThat;19import static org.assertj.core.api.Assertions.assertThatThrownBy;20public class InjectionAnnotationsTest {21    @FindBy(css = "css")22    private FluentWebElement css;23    @FindBy(xpath = "xpath")24    private FluentWebElement xpath;25    @iOSXCUITFindBy(accessibility = "iosAccessibilityId")26    private FluentWebElement iosAccessibilityId;27    @iOSXCUITFindBys({@iOSXCUITBy(id = "oneline"), @iOSXCUITBy(className = "small")})28    private FluentWebElement iosFindBys;29    @AndroidFindBy(uiAutomator = "androidUiAutomator")30    private FluentWebElement androidUiAutomator;31    @WindowsFindBy(windowsAutomation = "windows")32    private FluentWebElement windowsAutomation;33    @AndroidFindBy(accessibility = "android")34    @iOSXCUITFindBy(tagName = "ios")35    private FluentWebElement multiPlatformElement;36    @Test37    public void shouldInjectCssField() throws NoSuchFieldException {38        Field cssField = this.getClass().getDeclaredField("css");39        InjectionAnnotations annotations = new InjectionAnnotations(cssField, null);40        By by = annotations.buildBy();41        assertThat(by).isInstanceOf(By.ByCssSelector.class).isEqualTo(By.cssSelector("css"));42    }43    @Test44    public void shouldInjectXpathField() throws NoSuchFieldException {45        Field xpathField = this.getClass().getDeclaredField("xpath");46        InjectionAnnotations annotations = new InjectionAnnotations(xpathField, null);47        By by = annotations.buildBy();48        assertThat(by).isInstanceOf(By.ByXPath.class).isEqualTo(By.xpath("xpath"));49    }50    @Test51    public void shouldInjectIosAccessibilityIdField() throws NoSuchFieldException {52        Field accessibilityField = this.getClass().getDeclaredField("iosAccessibilityId");53        InjectionAnnotations annotations = new InjectionAnnotations(accessibilityField, getIosCapablities());54        By by = annotations.buildBy();55        assertThat(by).isInstanceOf(ContentMappedBy.class)56                .isEqualTo(new ByChained(AppiumBy.accessibilityId("iosAccessibilityId")));57    }58    @Test59    public void shouldInjectIosFindAllField() throws NoSuchFieldException {60        Field iosFindAllField = this.getClass().getDeclaredField("iosFindBys");61        InjectionAnnotations annotations = new InjectionAnnotations(iosFindAllField, getIosCapablities());62        By by = annotations.buildBy();63        assertThat(by).isInstanceOf(ContentMappedBy.class);64        ByChained expectedBy = new ByChained(new ByChained(MobileBy.id("oneline"), MobileBy.className("small")));65        assertThat(by).isEqualTo(expectedBy);66    }67    @Test68    public void shouldInjectAndroidAccessibilityIdField() throws NoSuchFieldException {69        Field uiAutomator = this.getClass().getDeclaredField("androidUiAutomator");70        InjectionAnnotations annotations = new InjectionAnnotations(uiAutomator, getAndroidCapablities());71        By by = annotations.buildBy();72        assertThat(by).isInstanceOf(ContentMappedBy.class)73                .isEqualTo(new ByChained(AppiumBy.androidUIAutomator("androidUiAutomator")));74    }75    @Test76    @Ignore77    public void shouldInjectWindowsAutomationField() throws NoSuchFieldException {78        Field windowsField = this.getClass().getDeclaredField("windowsAutomation");79        InjectionAnnotations annotations = new InjectionAnnotations(windowsField, getWindowsCapabilities());80        By by = annotations.buildBy();81        assertThat(by).isInstanceOf(ContentMappedBy.class)82                .isEqualTo(new ByChained(MobileBy.ByWindowsAutomation.windowsAutomation("windowsAutomation")));83    }84    @Test85    public void shouldThrowExceptionWhenCapabilitiesAreIncomplete() throws NoSuchFieldException {86        Field androidUiAutomatorField = this.getClass().getDeclaredField("androidUiAutomator");87        assertThatThrownBy(() -> new InjectionAnnotations(androidUiAutomatorField, getIncompleteAndroidCapabilties()))88                .isInstanceOf(ConfigurationException.class)89                .hasMessageContaining("You have annotated elements with Appium @FindBys but capabilities are incomplete");90    }91    @Test92    public void voidShouldPickCorrectSelectorWhenOnMultiplePlatform() throws NoSuchFieldException {93        Field field = this.getClass().getDeclaredField("multiPlatformElement");94        By androidBy = new InjectionAnnotations(field, getAndroidCapablities()).buildBy();95        assertThat(androidBy).isEqualTo(new ByChained(AppiumBy.accessibilityId("android")));...ContentMappedBy.java
Source:ContentMappedBy.java  
...21import org.openqa.selenium.WebElement;22import java.util.List;23import java.util.Map;24import javax.annotation.Nonnull;25public class ContentMappedBy extends By {26    private final Map<ContentType, By> map;27    private ContentType currentContent = NATIVE_MOBILE_SPECIFIC;28    public ContentMappedBy(Map<ContentType, By> map) {29        this.map = map;30    }31    /**32     * This method sets required content type for the further searching.33     * @param type required content type {@link ContentType}34     * @return self-reference.35     */36    public By useContent(@Nonnull ContentType type) {37        checkNotNull(type);38        currentContent = type;39        return this;40    }41    @Override public WebElement findElement(SearchContext context) {42        return context.findElement(map.get(currentContent));...ContentMappedBy
Using AI Code Generation
1@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.android.calculator2:id/digit_1\")")2@iOSFindBy(uiAutomator = ".buttons()[\"1\"]")3@ContentMappedBy(accessibility = "1")4public MobileElement one;5@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.android.calculator2:id/digit_1\")")6@iOSFindBy(uiAutomator = ".buttons()[\"1\"]")7@ContentMappedBy(accessibility = "1")8public MobileElement one;9@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.android.calculator2:id/digit_1\")")10@iOSFindBy(uiAutomator = ".buttons()[\"1\"]")11@ContentMappedBy(accessibility = "1")12public MobileElement one;13@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.android.calculator2:id/digit_1\")")14@iOSFindBy(uiAutomator = ".buttons()[\"1\"]")15@ContentMappedBy(accessibility = "1")16public MobileElement one;17@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.android.calculator2:id/digit_1\")")18@iOSFindBy(uiAutomator = ".buttons()[\"1\"]")19@ContentMappedBy(accessibility = "1")20public MobileElement one;21@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"com.android.calculator2:id/digit_1\")")22@iOSFindBy(uiAutomator = ".buttons()[\"1\"]")23@ContentMappedBy(accessibility = "1")24public MobileElement one;ContentMappedBy
Using AI Code Generation
1@AndroidFindBy(contentMappedBy = ContentMappedBy.ACCESSIBILITY_ID)2public MobileElement element;3@AndroidFindBy(contentMappedBy = ContentMappedBy.ID)4public MobileElement element;5@AndroidFindBy(contentMappedBy = ContentMappedBy.XPATH)6public MobileElement element;7@AndroidFindBy(contentMappedBy = ContentMappedBy.CLASS)8public MobileElement element;9@AndroidFindBy(contentMappedBy = ContentMappedBy.NAME)10public MobileElement element;11@AndroidFindBy(contentMappedBy = ContentMappedBy.TEXT)12public MobileElement element;13@AndroidFindBy(contentMappedBy = ContentMappedBy.DESCRIPTION)14public MobileElement element;15@AndroidFindBy(contentMappedBy = ContentMappedBy.CUSTOM)16public MobileElement element;17@AndroidFindBy(contentMappedBy = ContentMappedBy.IMAGE)18public MobileElement element;19@AndroidFindBy(contentMappedBy = ContentMappedBy.IMAGE_ALT)20public MobileElement element;21@AndroidFindBy(contentMappedBy = ContentMappedBy.IMAGE_CONTENT_DESCRIPTION)22public MobileElement element;23@AndroidFindBy(contentMappedBy = ContentMappedBy.IMAGE_LABEL)24public MobileElement element;25@AndroidFindBy(contentMappedBy = ContentMappedBy.IMAGE_NAME)26public MobileElement element;27@AndroidFindBy(contentMappedBy = ContentContentMappedBy
Using AI Code Generation
1public class ContentMappedBy {2    public static By contentDesc(String contentDesc) {3        return new ByAndroidUIAutomator("new UiSelector().description(\"" + contentDesc + "\")");4    }5}6public class ContentMappedBy {7    public static By contentDesc(String contentDesc) {8        return new ByAndroidUIAutomator("new UiSelector().description(\"" + contentDesc + "\")");9    }10}11public class ContentMappedBy {12    public static By contentDesc(String contentDesc) {13        return new ByAndroidUIAutomator("new UiSelector().description(\"" + contentDesc + "\")");14    }15}16public class ContentMappedBy {17    public static By contentDesc(String contentDesc) {18        return new ByAndroidUIAutomator("new UiSelector().description(\"" + contentDesc + "\")");19    }20}21public class ContentMappedBy {22    public static By contentDesc(String contentDesc) {23        return new ByAndroidUIAutomator("new UiSelector().description(\"" + contentDesc + "\")");24    }25}26public class ContentMappedBy {27    public static By contentDesc(String contentDesc) {28        return new ByAndroidUIAutomator("new UiSelector().description(\"" + contentDesc + "\")");29    }30}31public class ContentMappedBy {32    public static By contentDesc(String contentDesc) {33        return new ByAndroidUIAutomator("new UiSelector().description(\"" + contentDesc + "\")");34    }35}36public class ContentMappedBy {ContentMappedBy
Using AI Code Generation
1import io.appium.java_client.pagefactory.bys.ContentMappedBy;2import org.openqa.selenium.By;3public class ContentMappedByExample {4    @ContentMappedBy(androidUIAutomator = "new UiSelector().text(\"Some text\")")5    private By androidBy;6    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Some text\"`]")7    private By iOSBy;8    @ContentMappedBy(iOSNsPredicate = "label == \"Some text\"")9    private By iOSNsPredicateBy;10}11import io.appium.java_client.pagefactory.bys.ContentMappedBy12import org.openqa.selenium.By13class ContentMappedByExample {14    @ContentMappedBy(androidUIAutomator = "new UiSelector().text(\"Some text\")")15    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Some text\"`]")16    @ContentMappedBy(iOSNsPredicate = "label == \"Some text\"")17}18import io.appium.java_client.pagefactory.bys.ContentMappedBy19import org.openqa.selenium.By20class ContentMappedByExample {21    ContentMappedBy(androidUIutomator = "ew UiSelector().text(\"Some text\")")22    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Some text\"`]")23    @ContentMappedBy(iOSNsPreicate = "label == \"Some text\"")24}25import io.appium.java_client.pagefactory.bys.ContentMappedBy26import org.openqa.selenium.By27class ContentMappedByExample {28    @ContentMappedBy(androidUIAutomator = "new UiSelector().text(\"Some text\")")29    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`ContentMappedBy
Using AI Code Generation
1import io.appium.java_client.pagefactory.bys.ContentMappedBy;2import org.openqa.selenium.By;3public class ContentMappedByExample {4    @ContentMappedBy(androidUIAutomator = "new UiSelector().text(\"Some text\")")5    private By androidBy;6    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Some text\"`]")7    private By iOSBy;8    @ContentMappedBy(iOSNsPredicate = "label == \"Some text\"")9    private By iOSNsPredicateBy;10}11import io.appium.java_client.pagefactory.bys.ContentMappedBy12import org.openqa.selenium.By13class ContentMappedByExample {14    @ContentMappedBy(androidUIAutomator = "new UiSelector().text(\"Some text\")")15    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Some text\"`]")16    @ContentMappedBy(iOSNsPredicate = "label == \"Some text\"")17}18import io.appium.java_client.pagefactory.bys.ContentMappedBy19import org.openqa.selenium.By20class ContentMappedByExample {21    @ContentMappedBy(androidUIAutomator = "new UiSelector().text(\"Some text\")")22    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`label == \"Some text\"`]")23    @ContentMappedBy(iOSNsPredicate = "label == \"Some text\"")24}25import io.appium.java_client.pagefactory.bys.ContentMappedBy26import org.openqa.selenium.By27class ContentMappedByExample {28    @ContentMappedBy(androidUIAutomator = "new UiSelector().text(\"Some text\")")29    @ContentMappedBy(iOSClassChain = "**/XCUIElementTypeStaticText[`ContentMappedBy
Using AI Code Generation
1@AndroidFindBy(className = "android.widget.TextView")2@iOSFindBy(accessibility = "test-ADD")3private MobileElement addBtn;4@AndroidFindBy(className = "android.widget.TextView")5@iOSFindBy(accessibility = "test-ADD")6private MobileElement addBtn;7@AndroidFindBy(className = "android.widget.TextView")8@iOSFindBy(accessibility = "test-ADD")9private MobileElement addBtn;10@AndroidFindBy(className = "android.widget.TextView")11@iOSFindBy(accessibility = "test-ADD")12private MobileElement addBtn;13@AndroidFindBy(className = "android.widget.TextView")14@iOSFindBy(accessibility = "test-ADD")15private MobileElement addBtn;16@AndroidFindBy(className = "android.widget.TextView")17@iOSFindBy(accessibility = "test-ADD")18private MobileElement addBtn;19@AndroidFindBy(className = "android.widget.TextView")20@iOSFindBy(accessibility = "test-ADD")21private MobileElement addBtn;22@AndroidFindBy(className = "android.widget.TextView")23@iOSFindBy(accessibility = "test-ADD")24private MobileElement addBtn;25@AndroidFindBy(className = "android.widget.TextView")26@iOSFindBy(accessibility = "test-ADD")27private MobileElement addBtn;28@AndroidFindBy(className = "android.widget.TextView")29@iOSFindBy(accessibility = "test-ADD")30private MobileElement addBtn;31@AndroidFindBy(className = "android.widget.TextView")32@iOSFindBy(accessibility = "test-ADD")33private MobileElement addBtn;ContentMappedBy
Using AI Code Generation
1package appium.java;2import io.appium.java_client.pagefactory.AppiumFieldDecorator;3import io.appium.java_client.pagefactory.ContentMappedBy;4import io.appium.java_client.pagefactory.bys.*;5import org.openqa.selenium.WebDriver;6import org.openqa.selenium.WebElement;7import org.openqa.selenium.support.FindBy;8import org.openqa.selenium.support.PageFactory;9public class AppiumJava {10    public AppiumJava(WebDriver driver){11        PageFactory.initElements(new AppiumFieldDecorator(driver), this);12    }13    @ContentMappedBy(android = @AndroidFindBy(id = "com.android.calculator2:id/digit_1"),14    public WebElement one;15    @ContentMappedBy(android = @AndroidFindBy(id = "com.android.calculator2:id/digit_2"),ContentMappedBy
Using AI Code Generation
1@AndroidFindBy(contentMappedBy = ContentMappedBy.CONTENT_DESC)2public WebElement contentDescElement;3@AndroidFindBy(contentMappedBy = ContentMappedBy.TEXT)4public WebElement textElement;5@AndroidFindBy(contentMappedBy = ContentMappedBy.CLASS_NAME)6public WebElement classNameElement;7@AndroidFindBy(contentMappedBy = ContentMappedBy.NAME)8public WebElement nameElement;9@AndroidFindBy(contentMappedBy = ContentMappedBy.PACKAGE_NAME)10public WebElement packageNameElement;11@AndroidFindBy(contentMappedBy = ContentMappedBy.RESOnRCE_ID)12publac WebElement resourceIdElement;13@AndroidFindBy(contentMappedBy = ContentMappedBy.CONTENT_DEmC)14public WebElement contentDescElement;15@AndroidFindBy(contentMappedBy = ContentMappedBy.TEXT)16public WebElement textElement;17@AndroidFindBy(contentMappedBy = ContentMappedBy.CLASS_NAME)18public WebElement classNameElement;19public WebElement nameElement;20    public WebElement two;21    @ContentMappedBy(android = @AndroidFindBy(id = "com.android.calculator2:id/digit_3"),22    public WebElement three;23    @ContentMappedBy(android = @AndroidFindBy(id = "com.android.calculator2:id/digit_4"),24    public WebElement four;25    @ContentMappedBy(android = @AndroidFindBy(id = "com.android.calculator2:id/digit_5"),26    public WebElement five;27    @ContentMappedBy(android = @AndroidFindBy(id = "com.android.calculator2:id/digit_6"),28    public WebElement six;29    @ContentMappedBy(android = @AndroidFindBy(id = "com.android.calculator2:id/digit_7"),30    public WebElement seven;31    @ContentMappedBy(android =ContentMappedBy
Using AI Code Generation
1@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))2public WebElement searchButton;3@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))4public WebElement searchButton;5@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))6public WebElement searchButton;7@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))8public WebElement searchButton;9@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))10public WebElement searchButton;11@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))12public WebElement searchButton;13@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))14public WebElement searchButton;15@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))ContentMappedBy
Using AI Code Generation
1By by = ContentMappedBy.ContentMap(android:id/text1);2WebElement element = driver.findElement(by);3element.click();4@AndroidFindBy(id = "android:id/text1")5WebElement element;6element.click();7@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")8WebElement element;9element.click();10@AndroidFindBy(id = "android:id/text1", className = "android.widget.TextView")11WebElement element;12element.click();13@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")14WebElement element;15element.click();16@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")17WebElement element;18element.click();19@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")20WebElement element;21element.click();22@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")23WebElement element;24element.click();25@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")26WebElement element;27element.click();28@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")29WebElement element;30element.click();31@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")32WebElement element;33element.click();34@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))35public WebElement searchButton;36@AndroidFindBy(contentMappedBy = @ContentMappedBy(using = "new UiSelector().description(\"Search\")"))37public WebElement searchButton;ContentMappedBy
Using AI Code Generation
1@AndroidFindBy(contentMappedBy = ContentMappedBy.AccessibilityId)2private MobileElement element;3@AndroidFindBy(accessibility = "content-desc")4private MobileElement element;5@AndroidFindBy(uiAutomator = "content-desc")6private MobileElement element;7@AndroidFindBy(uiAutomator = "new UiSelector().content-desc(\"content-desc\")")8private MobileElement element;9@AndroidFindBy(uiAutomator = "new UiSelector().resourceId(\"resource-id\")")10private MobileElement element;11@AndroidFindBy(uiAutomator = "new UiSelector().className(\"android.widget.TextView\")")12private MobileElement element;13@AndroidFindBy(uiAutomator = "new UiSelector().text(\"text\")")14private MobileElement element;15@AndroidFindBy(uiAutomator = "new UiSelector().description(\"description\")")16private MobileElement element;17@AndroidFindBy(uiAutomator = "new UiSelector().checkable(\"true\")")18private MobileElement element;ContentMappedBy
Using AI Code Generation
1By by = ContentMappedBy.ContentMap(android:id/text1);2WebElement element = driver.findElement(by);3element.click();4@AndroidFindBy(id = "android:id/text1")5WebElement element;6element.click();7@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")8WebElement element;9element.click();10@AndroidFindBy(id = "android:id/text1", className = "android.widget.TextView")11WebElement element;12element.click();13@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")14WebElement element;15element.click();16@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")17WebElement element;18element.click();19@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")20WebElement element;21element.click();22@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")23WebElement element;24element.click();25@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")26WebElement element;27element.click();28@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")29WebElement element;30element.click();31@AndroidFindBy(uiAutomator = "new UiSelector().description(\"Animation\")")32WebElement element;33element.click();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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
