How to use toString method of io.appium.java_client.MobileBy.ByImage class

Best io.appium code snippet using io.appium.java_client.MobileBy.ByImage.toString

Run io.appium automation tests on LambdaTest cloud grid

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

MobileBy.java

Source: MobileBy.java Github

copy
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * See the NOTICE file distributed with this work for additional
5 * information regarding copyright ownership.
6 * You may obtain a copy of the License at
7 *
8 *     http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package io.appium.java_client;
18
19import lombok.AccessLevel;
20import lombok.Getter;
21import org.apache.commons.lang3.StringUtils;
22import org.openqa.selenium.By;
23import org.openqa.selenium.SearchContext;
24import org.openqa.selenium.WebDriverException;
25import org.openqa.selenium.WebElement;
26
27import java.io.Serializable;
28import java.util.List;
29
30@SuppressWarnings("serial")
31public abstract class MobileBy extends By {
32
33    private static final String ERROR_TEXT = "The class %s of the given context "
34        + "doesn't implement %s nor %s. Sorry. It is impossible to find something.";
35
36    @Getter(AccessLevel.PROTECTED) private final String locatorString;
37    private final MobileSelector selector;
38
39    private static IllegalArgumentException formIllegalArgumentException(Class<?> givenClass,
40        Class<?> class1, Class<?> class2) {
41        return new IllegalArgumentException(String.format(ERROR_TEXT, givenClass.getCanonicalName(),
42            class1.getCanonicalName(), class2.getCanonicalName()));
43    }
44
45    protected MobileBy(MobileSelector selector, String locatorString) {
46        if (StringUtils.isBlank(locatorString)) {
47            throw new IllegalArgumentException("Must supply a not empty locator value.");
48        }
49        this.locatorString = locatorString;
50        this.selector = selector;
51    }
52
53    @SuppressWarnings("unchecked")
54    @Override public List<WebElement> findElements(SearchContext context) {
55        return (List<WebElement>) ((FindsByFluentSelector<?>) context)
56                .findElements(selector.toString(), getLocatorString());
57    }
58
59    @Override public WebElement findElement(SearchContext context) {
60        return ((FindsByFluentSelector<?>) context)
61                .findElement(selector.toString(), getLocatorString());
62    }
63
64    /**
65     * Refer to https://developer.android.com/training/testing/ui-automator
66     * @param uiautomatorText is Android UIAutomator string
67     * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}
68     */
69    public static By AndroidUIAutomator(final String uiautomatorText) {
70        return new ByAndroidUIAutomator(uiautomatorText);
71    }
72
73    /**
74     * About Android accessibility
75     * https://developer.android.com/intl/ru/training/accessibility/accessible-app.html
76     * About iOS accessibility
77     * https://developer.apple.com/library/ios/documentation/UIKit/Reference/
78     * UIAccessibilityIdentification_Protocol/index.html
79     * @param accessibilityId id is a convenient UI automation accessibility Id.
80     * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidUIAutomator}
81     */
82    public static By AccessibilityId(final String accessibilityId) {
83        return new ByAccessibilityId(accessibilityId);
84    }
85
86    /**
87     * This locator strategy is available in XCUITest Driver mode.
88     * @param iOSClassChainString is a valid class chain locator string.
89     *                            See <a href="https://github.com/facebookarchive/WebDriverAgent/wiki/Class-Chain-Queries-Construction-Rules">
90     *                            the documentation</a> for more details
91     * @return an instance of {@link io.appium.java_client.MobileBy.ByIosClassChain}
92     */
93    public static By iOSClassChain(final String iOSClassChainString) {
94        return new ByIosClassChain(iOSClassChainString);
95    }
96
97    /**
98     * This locator strategy is only available in Espresso Driver mode.
99     * @param dataMatcherString is a valid json string detailing hamcrest matcher for Espresso onData().
100     *                            See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
101     *                            the documentation</a> for more details
102     * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidDataMatcher}
103     */
104    public static By androidDataMatcher(final String dataMatcherString) {
105        return new ByAndroidDataMatcher(dataMatcherString);
106    }
107
108    /**
109     * This locator strategy is only available in Espresso Driver mode.
110     * @param viewMatcherString is a valid json string detailing hamcrest matcher for Espresso onView().
111     *                            See <a href="http://appium.io/docs/en/writing-running-appium/android/espresso-datamatcher-selector/">
112     *                            the documentation</a> for more details
113     * @return an instance of {@link io.appium.java_client.MobileBy.ByAndroidViewMatcher}
114     */
115    public static By androidViewMatcher(final String viewMatcherString) {
116        return new ByAndroidViewMatcher(viewMatcherString);
117    }
118
119    /**
120    * This locator strategy is available in XCUITest Driver mode.
121    * @param iOSNsPredicateString is an an iOS NsPredicate String
122    * @return an instance of {@link io.appium.java_client.MobileBy.ByIosNsPredicate}
123    */
124    public static By iOSNsPredicateString(final String iOSNsPredicateString) {
125        return new ByIosNsPredicate(iOSNsPredicateString);
126    }
127
128    public static By windowsAutomation(final String windowsAutomation) {
129        return new ByWindowsAutomation(windowsAutomation);
130    }
131
132    /**
133     * This locator strategy is available in Espresso Driver mode.
134     * @since Appium 1.8.2 beta
135     * @param tag is an view tag string
136     * @return an instance of {@link ByAndroidViewTag}
137     */
138    public static By AndroidViewTag(final String tag) {
139        return new ByAndroidViewTag(tag);
140    }
141
142    /**
143     * This locator strategy is available only if OpenCV libraries and
144     * NodeJS bindings are installed on the server machine.
145     *
146     * @see <a href="https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/image-comparison.md">
147     * The documentation on Image Comparison Features</a>
148     * @see <a href="https://github.com/appium/appium-base-driver/blob/master/lib/basedriver/device-settings.js">
149     * The settings available for lookup fine-tuning</a>
150     * @since Appium 1.8.2
151     * @param b64Template base64-encoded template image string. Supported image formats are the same
152     *                    as for OpenCV library.
153     * @return an instance of {@link ByImage}
154     */
155    public static By image(final String b64Template) {
156        return new ByImage(b64Template);
157    }
158
159    /**
160     * This type of locator requires the use of the 'customFindModules' capability and a
161     * separately-installed element finding plugin.
162     *
163     * @param selector selector to pass to the custom element finding plugin
164     * @return an instance of {@link ByCustom}
165     * @since Appium 1.9.2
166     */
167    public static By custom(final String selector) {
168        return new ByCustom(selector);
169    }
170
171
172    public static class ByAndroidUIAutomator extends MobileBy implements Serializable {
173
174
175        public ByAndroidUIAutomator(String uiautomatorText) {
176            super(MobileSelector.ANDROID_UI_AUTOMATOR, uiautomatorText);
177        }
178
179        /**
180         * {@inheritDoc}
181         *
182         * @throws WebDriverException when current session doesn't support the given selector or when
183         *      value of the selector is not consistent.
184         * @throws IllegalArgumentException when it is impossible to find something on the given
185         * {@link SearchContext} instance
186         */
187        @SuppressWarnings("unchecked")
188        @Override
189        public List<WebElement> findElements(SearchContext context) throws WebDriverException,
190            IllegalArgumentException {
191            Class<?> contextClass = context.getClass();
192
193            if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {
194                return FindsByAndroidUIAutomator.class.cast(context)
195                    .findElementsByAndroidUIAutomator(getLocatorString());
196            }
197
198            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
199                return super.findElements(context);
200            }
201
202            throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,
203                FindsByFluentSelector.class);
204        }
205
206        /**
207         * {@inheritDoc}
208         *
209         * @throws WebDriverException when current session doesn't support the given selector or when
210         *      value of the selector is not consistent.
211         * @throws IllegalArgumentException when it is impossible to find something on the given
212         * {@link SearchContext} instance
213         */
214        @Override public WebElement findElement(SearchContext context) throws WebDriverException,
215            IllegalArgumentException {
216            Class<?> contextClass = context.getClass();
217
218            if (FindsByAndroidUIAutomator.class.isAssignableFrom(contextClass)) {
219                return FindsByAndroidUIAutomator.class.cast(context)
220                    .findElementByAndroidUIAutomator(getLocatorString());
221            }
222
223            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
224                return super.findElement(context);
225            }
226
227            throw formIllegalArgumentException(contextClass, FindsByAndroidUIAutomator.class,
228                FindsByFluentSelector.class);
229        }
230
231        @Override public String toString() {
232            return "By.AndroidUIAutomator: " + getLocatorString();
233        }
234    }
235
236
237    public static class ByAccessibilityId extends MobileBy implements Serializable {
238
239        public ByAccessibilityId(String accessibilityId) {
240            super(MobileSelector.ACCESSIBILITY, accessibilityId);
241        }
242
243        /**
244         * {@inheritDoc}
245         *
246         * @throws WebDriverException when current session doesn't support the given selector or when
247         *      value of the selector is not consistent.
248         * @throws IllegalArgumentException when it is impossible to find something on the given
249         * {@link SearchContext} instance
250         */
251        @SuppressWarnings("unchecked")
252        @Override
253        public List<WebElement> findElements(SearchContext context) throws WebDriverException,
254            IllegalArgumentException {
255            Class<?> contextClass = context.getClass();
256
257            if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {
258                return FindsByAccessibilityId.class.cast(context)
259                    .findElementsByAccessibilityId(getLocatorString());
260            }
261
262            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
263                return super.findElements(context);
264            }
265
266            throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,
267                FindsByFluentSelector.class);
268        }
269
270        /**
271         * {@inheritDoc}
272         *
273         * @throws WebDriverException when current session doesn't support the given selector or when
274         *      value of the selector is not consistent.
275         * @throws IllegalArgumentException when it is impossible to find something on the given
276         * {@link SearchContext} instance
277         */
278        @Override public WebElement findElement(SearchContext context) throws WebDriverException,
279            IllegalArgumentException {
280            Class<?> contextClass = context.getClass();
281
282            if (FindsByAccessibilityId.class.isAssignableFrom(contextClass)) {
283                return FindsByAccessibilityId.class.cast(context)
284                    .findElementByAccessibilityId(getLocatorString());
285            }
286
287            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
288                return super.findElement(context);
289            }
290
291            throw formIllegalArgumentException(contextClass, FindsByAccessibilityId.class,
292                FindsByFluentSelector.class);
293        }
294
295        @Override public String toString() {
296            return "By.AccessibilityId: " + getLocatorString();
297        }
298    }
299
300    public static class ByIosClassChain extends MobileBy implements Serializable {
301
302        protected ByIosClassChain(String locatorString) {
303            super(MobileSelector.IOS_CLASS_CHAIN, locatorString);
304        }
305
306        /**
307         * {@inheritDoc}
308         *
309         * @throws WebDriverException when current session doesn't support the given selector or when
310         *      value of the selector is not consistent.
311         * @throws IllegalArgumentException when it is impossible to find something on the given
312         * {@link SearchContext} instance
313         */
314        @SuppressWarnings("unchecked")
315        @Override public List<WebElement> findElements(SearchContext context) {
316            Class<?> contextClass = context.getClass();
317
318            if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {
319                return FindsByIosClassChain.class.cast(context)
320                        .findElementsByIosClassChain(getLocatorString());
321            }
322
323            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
324                return super.findElements(context);
325            }
326
327            throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,
328                    FindsByFluentSelector.class);
329        }
330
331        /**
332         * {@inheritDoc}
333         *
334         * @throws WebDriverException when current session doesn't support the given selector or when
335         *      value of the selector is not consistent.
336         * @throws IllegalArgumentException when it is impossible to find something on the given
337         * {@link SearchContext} instance
338         */
339        @Override public WebElement findElement(SearchContext context) {
340            Class<?> contextClass = context.getClass();
341
342            if (FindsByIosClassChain.class.isAssignableFrom(contextClass)) {
343                return FindsByIosClassChain.class.cast(context)
344                        .findElementByIosClassChain(getLocatorString());
345            }
346
347            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
348                return super.findElement(context);
349            }
350
351            throw formIllegalArgumentException(contextClass, FindsByIosClassChain.class,
352                    FindsByFluentSelector.class);
353        }
354
355        @Override public String toString() {
356            return "By.IosClassChain: " + getLocatorString();
357        }
358    }
359
360    public static class ByAndroidDataMatcher extends MobileBy implements Serializable {
361
362        protected ByAndroidDataMatcher(String locatorString) {
363            super(MobileSelector.ANDROID_DATA_MATCHER, locatorString);
364        }
365
366        /**
367         * {@inheritDoc}
368         *
369         * @throws WebDriverException when current session doesn't support the given selector or when
370         *      value of the selector is not consistent.
371         * @throws IllegalArgumentException when it is impossible to find something on the given
372         * {@link SearchContext} instance
373         */
374        @SuppressWarnings("unchecked")
375        @Override public List<WebElement> findElements(SearchContext context) {
376            Class<?> contextClass = context.getClass();
377
378            if (FindsByAndroidDataMatcher.class.isAssignableFrom(contextClass)) {
379                return FindsByAndroidDataMatcher.class.cast(context)
380                        .findElementsByAndroidDataMatcher(getLocatorString());
381            }
382
383            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
384                return super.findElements(context);
385            }
386
387            throw formIllegalArgumentException(contextClass, FindsByAndroidDataMatcher.class,
388                    FindsByFluentSelector.class);
389        }
390
391        /**
392         * {@inheritDoc}
393         *
394         * @throws WebDriverException when current session doesn't support the given selector or when
395         *      value of the selector is not consistent.
396         * @throws IllegalArgumentException when it is impossible to find something on the given
397         * {@link SearchContext} instance
398         */
399        @Override public WebElement findElement(SearchContext context) {
400            Class<?> contextClass = context.getClass();
401
402            if (FindsByAndroidDataMatcher.class.isAssignableFrom(contextClass)) {
403                return FindsByAndroidDataMatcher.class.cast(context)
404                        .findElementByAndroidDataMatcher(getLocatorString());
405            }
406
407            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
408                return super.findElement(context);
409            }
410
411            throw formIllegalArgumentException(contextClass, FindsByAndroidDataMatcher.class,
412                    FindsByFluentSelector.class);
413        }
414
415        @Override public String toString() {
416            return "By.FindsByAndroidDataMatcher: " + getLocatorString();
417        }
418    }
419
420    public static class ByAndroidViewMatcher extends MobileBy implements Serializable {
421
422        protected ByAndroidViewMatcher(String locatorString) {
423            super(MobileSelector.ANDROID_VIEW_MATCHER, locatorString);
424        }
425
426        /**
427         * {@inheritDoc}
428         *
429         * @throws WebDriverException when current session doesn't support the given selector or when
430         *      value of the selector is not consistent.
431         * @throws IllegalArgumentException when it is impossible to find something on the given
432         * {@link SearchContext} instance
433         */
434        @SuppressWarnings("unchecked")
435        @Override public List<WebElement> findElements(SearchContext context) {
436            Class<?> contextClass = context.getClass();
437
438            if (FindsByAndroidViewMatcher.class.isAssignableFrom(contextClass)) {
439                return FindsByAndroidViewMatcher.class.cast(context)
440                    .findElementsByAndroidViewMatcher(getLocatorString());
441            }
442
443            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
444                return super.findElements(context);
445            }
446
447            throw formIllegalArgumentException(contextClass, FindsByAndroidViewMatcher.class,
448                FindsByFluentSelector.class);
449        }
450
451        /**
452         * {@inheritDoc}
453         *
454         * @throws WebDriverException when current session doesn't support the given selector or when
455         *      value of the selector is not consistent.
456         * @throws IllegalArgumentException when it is impossible to find something on the given
457         * {@link SearchContext} instance
458         */
459        @Override public WebElement findElement(SearchContext context) {
460            Class<?> contextClass = context.getClass();
461
462            if (FindsByAndroidViewMatcher.class.isAssignableFrom(contextClass)) {
463                return FindsByAndroidViewMatcher.class.cast(context)
464                    .findElementByAndroidViewMatcher(getLocatorString());
465            }
466
467            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
468                return super.findElement(context);
469            }
470
471            throw formIllegalArgumentException(contextClass, FindsByAndroidViewMatcher.class,
472                FindsByFluentSelector.class);
473        }
474
475        @Override public String toString() {
476            return "By.FindsByAndroidViewMatcher: " + getLocatorString();
477        }
478    }
479
480    public static class ByIosNsPredicate extends MobileBy implements Serializable {
481
482        protected ByIosNsPredicate(String locatorString) {
483            super(MobileSelector.IOS_PREDICATE_STRING, locatorString);
484        }
485
486        /**
487         * {@inheritDoc}
488         *
489         * @throws WebDriverException when current session doesn't support the given selector or when
490         *      value of the selector is not consistent.
491         * @throws IllegalArgumentException when it is impossible to find something on the given
492         * {@link SearchContext} instance
493         */
494        @SuppressWarnings("unchecked")
495        @Override public List<WebElement> findElements(SearchContext context) {
496            Class<?> contextClass = context.getClass();
497
498            if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {
499                return FindsByIosNSPredicate.class.cast(context)
500                        .findElementsByIosNsPredicate(getLocatorString());
501            }
502
503            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
504                return super.findElements(context);
505            }
506
507            throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,
508                    FindsByFluentSelector.class);
509        }
510
511        /**
512         * {@inheritDoc}
513         *
514         * @throws WebDriverException when current session doesn't support the given selector or when
515         *      value of the selector is not consistent.
516         * @throws IllegalArgumentException when it is impossible to find something on the given
517         * {@link SearchContext} instance
518         */
519        @Override public WebElement findElement(SearchContext context) {
520            Class<?> contextClass = context.getClass();
521
522            if (FindsByIosNSPredicate.class.isAssignableFrom(contextClass)) {
523                return FindsByIosNSPredicate.class.cast(context)
524                        .findElementByIosNsPredicate(getLocatorString());
525            }
526
527            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
528                return super.findElement(context);
529            }
530
531            throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,
532                    FindsByFluentSelector.class);
533        }
534
535        @Override public String toString() {
536            return "By.IosNsPredicate: " + getLocatorString();
537        }
538    }
539
540    public static class ByWindowsAutomation extends MobileBy implements Serializable {
541
542        protected ByWindowsAutomation(String locatorString) {
543            super(MobileSelector.WINDOWS_UI_AUTOMATION, locatorString);
544        }
545
546        /**
547         * {@inheritDoc}
548         *
549         * @throws WebDriverException when current session doesn't support the given selector or when
550         *      value of the selector is not consistent.
551         * @throws IllegalArgumentException when it is impossible to find something on the given
552         * {@link SearchContext} instance
553         */
554        @SuppressWarnings("unchecked")
555        @Override public List<WebElement> findElements(SearchContext context) {
556            Class<?> contextClass = context.getClass();
557
558            if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {
559                return FindsByWindowsAutomation.class.cast(context)
560                    .findElementsByWindowsUIAutomation(getLocatorString());
561            }
562
563            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
564                return super.findElements(context);
565            }
566
567            throw formIllegalArgumentException(contextClass, FindsByWindowsAutomation.class,
568                FindsByFluentSelector.class);
569        }
570
571        /**
572         * {@inheritDoc}
573         *
574         * @throws WebDriverException when current session doesn't support the given selector or when
575         *      value of the selector is not consistent.
576         * @throws IllegalArgumentException when it is impossible to find something on the given
577         * {@link SearchContext} instance
578         */
579        @Override public WebElement findElement(SearchContext context) {
580            Class<?> contextClass = context.getClass();
581
582            if (FindsByWindowsAutomation.class.isAssignableFrom(contextClass)) {
583                return FindsByWindowsAutomation.class.cast(context)
584                    .findElementByWindowsUIAutomation(getLocatorString());
585            }
586
587            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
588                return super.findElement(context);
589            }
590
591            throw formIllegalArgumentException(contextClass, FindsByIosNSPredicate.class,
592                FindsByWindowsAutomation.class);
593        }
594    }
595
596    public static class ByImage extends MobileBy implements Serializable {
597
598        protected ByImage(String b64Template) {
599            super(MobileSelector.IMAGE, b64Template);
600        }
601
602        /**
603         * {@inheritDoc}
604         *
605         * @throws WebDriverException when current session doesn't support the given selector or when
606         *      value of the selector is not consistent.
607         * @throws IllegalArgumentException when it is impossible to find something on the given
608         * {@link SearchContext} instance
609         */
610        @SuppressWarnings("unchecked")
611        @Override public List<WebElement> findElements(SearchContext context) {
612            Class<?> contextClass = context.getClass();
613
614            if (FindsByImage.class.isAssignableFrom(contextClass)) {
615                return FindsByImage.class.cast(context).findElementsByImage(getLocatorString());
616            }
617
618            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
619                return super.findElements(context);
620            }
621
622            throw formIllegalArgumentException(contextClass, FindsByImage.class, FindsByFluentSelector.class);
623        }
624
625        /**
626         * {@inheritDoc}
627         *
628         * @throws WebDriverException when current session doesn't support the given selector or when
629         *      value of the selector is not consistent.
630         * @throws IllegalArgumentException when it is impossible to find something on the given
631         * {@link SearchContext} instance
632         */
633        @Override public WebElement findElement(SearchContext context) {
634            Class<?> contextClass = context.getClass();
635
636            if (FindsByImage.class.isAssignableFrom(contextClass)) {
637                return FindsByImage.class.cast(context).findElementByImage(getLocatorString());
638            }
639
640            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
641                return super.findElement(context);
642            }
643
644            throw formIllegalArgumentException(contextClass, FindsByImage.class, FindsByFluentSelector.class);
645        }
646
647        @Override public String toString() {
648            return "By.Image: " + getLocatorString();
649        }
650    }
651
652    public static class ByCustom extends MobileBy implements Serializable {
653
654        protected ByCustom(String selector) {
655            super(MobileSelector.CUSTOM, selector);
656        }
657
658        /**
659         * {@inheritDoc}
660         *
661         * @throws WebDriverException when current session doesn't support the given selector or when
662         *      value of the selector is not consistent.
663         * @throws IllegalArgumentException when it is impossible to find something on the given
664         * {@link SearchContext} instance
665         */
666        @SuppressWarnings("unchecked")
667        @Override public List<WebElement> findElements(SearchContext context) {
668            Class<?> contextClass = context.getClass();
669
670            if (FindsByCustom.class.isAssignableFrom(contextClass)) {
671                return FindsByCustom.class.cast(context).findElementsByCustom(getLocatorString());
672            }
673
674            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
675                return super.findElements(context);
676            }
677
678            throw formIllegalArgumentException(contextClass, FindsByCustom.class, FindsByFluentSelector.class);
679        }
680
681        /**
682         * {@inheritDoc}
683         *
684         * @throws WebDriverException when current session doesn't support the given selector or when
685         *      value of the selector is not consistent.
686         * @throws IllegalArgumentException when it is impossible to find something on the given
687         * {@link SearchContext} instance
688         */
689        @Override public WebElement findElement(SearchContext context) {
690            Class<?> contextClass = context.getClass();
691
692            if (FindsByCustom.class.isAssignableFrom(contextClass)) {
693                return FindsByCustom.class.cast(context).findElementByCustom(getLocatorString());
694            }
695
696            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
697                return super.findElement(context);
698            }
699
700            throw formIllegalArgumentException(contextClass, FindsByCustom.class, FindsByFluentSelector.class);
701        }
702
703        @Override public String toString() {
704            return "By.Custom: " + getLocatorString();
705        }
706    }
707
708    public static class ByAndroidViewTag extends MobileBy implements Serializable {
709
710        public ByAndroidViewTag(String tag) {
711            super(MobileSelector.ANDROID_VIEWTAG, tag);
712        }
713
714        /**
715         * {@inheritDoc}
716         *
717         * @throws WebDriverException when current session doesn't support the given selector or when
718         *      value of the selector is not consistent.
719         * @throws IllegalArgumentException when it is impossible to find something on the given
720         * {@link SearchContext} instance
721         */
722        @SuppressWarnings("unchecked")
723        @Override
724        public List<WebElement> findElements(SearchContext context) throws WebDriverException,
725                IllegalArgumentException {
726            Class<?> contextClass = context.getClass();
727
728            if (FindsByAndroidViewTag.class.isAssignableFrom(contextClass)) {
729                return FindsByAndroidViewTag.class.cast(context)
730                        .findElementsByAndroidViewTag(getLocatorString());
731            }
732
733            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
734                return super.findElements(context);
735            }
736
737            throw formIllegalArgumentException(contextClass, FindsByAndroidViewTag.class,
738                    FindsByFluentSelector.class);
739        }
740
741        /**
742         * {@inheritDoc}
743         *
744         * @throws WebDriverException when current session doesn't support the given selector or when
745         *      value of the selector is not consistent.
746         * @throws IllegalArgumentException when it is impossible to find something on the given
747         * {@link SearchContext} instance
748         */
749        @Override public WebElement findElement(SearchContext context) throws WebDriverException,
750                IllegalArgumentException {
751            Class<?> contextClass = context.getClass();
752
753            if (FindsByAndroidViewTag.class.isAssignableFrom(contextClass)) {
754                return FindsByAndroidViewTag.class.cast(context)
755                        .findElementByAndroidViewTag(getLocatorString());
756            }
757
758            if (FindsByFluentSelector.class.isAssignableFrom(contextClass)) {
759                return super.findElement(context);
760            }
761
762            throw formIllegalArgumentException(contextClass, FindsByAndroidViewTag.class,
763                    FindsByFluentSelector.class);
764        }
765
766        @Override public String toString() {
767            return "By.AndroidViewTag: " + getLocatorString();
768        }
769    }
770}
771
772
773
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used method in MobileBy.ByImage

Trigger toString code on LambdaTest Cloud Grid

Execute automation tests with toString on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)