1515# pylint: disable=abstract-method
1616
1717import json
18- from typing import TYPE_CHECKING , List , Optional
18+ from typing import TYPE_CHECKING , Any , List , Optional
1919
2020from appium .webdriver .common .mobileby import MobileBy
2121
2828class AndroidSearchContext (BaseSearchContext ):
2929 """Define search context for Android"""
3030
31+ def find_element_by_android_view_matcher (
32+ self , name : Optional [str ] = None , args : Optional [Any ] = None , className : Optional [str ] = None ) -> 'WebElement' :
33+ """Finds element by [onView](https://developer.android.com/training/testing/espresso/basics) in Android
34+
35+ It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
36+
37+ Args:
38+ name (:obj:`str`, optional): The name of a method to invoke.
39+ The method must return a Hamcrest
40+ [Matcher](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)
41+ args (:obj:`Any`, optional): The args provided to the method
42+ className (:obj:`str`, optional): The class name that the method is part of (defaults to `org.hamcrest.Matchers`).
43+ Can be fully qualified by having the androidx.test.espresso.matcher. prefix.
44+ If the prefix is not provided then it is going to be added implicitly.
45+ (e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers`
46+
47+ Returns:
48+ `appium.webdriver.webelement.WebElement`: The found element
49+
50+ Raises:
51+ TypeError - Raises a TypeError if the arguments are not validated for JSON format
52+
53+ Usage:
54+ driver.find_element_by_android_view_matcher(name='withText', args=['Accessibility'], className='ViewMatchers')
55+
56+ # To enable auto completion in PyCharm(IDE)
57+ :rtype: `appium.webdriver.webelement.WebElement`
58+ """
59+
60+ return self .find_element (
61+ by = MobileBy .ANDROID_VIEW_MATCHER ,
62+ value = self ._build_data_matcher (name = name , args = args , className = className )
63+ )
64+
3165 def find_element_by_android_data_matcher (
32- self , name : Optional [str ] = None , args : Optional [str ] = None , className : Optional [str ] = None ) -> 'WebElement' :
66+ self , name : Optional [str ] = None , args : Optional [Any ] = None , className : Optional [str ] = None ) -> 'WebElement' :
3367 """Finds element by [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
3468
3569 It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
@@ -38,7 +72,7 @@ def find_element_by_android_data_matcher(
3872 name (:obj:`str`, optional): The name of a method to invoke.
3973 The method must return a Hamcrest
4074 [Matcher](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)
41- args (:obj:`str `, optional): The args provided to the method
75+ args (:obj:`Any `, optional): The args provided to the method
4276 className (:obj:`str`, optional): The class name that the method is part of (defaults to `org.hamcrest.Matchers`).
4377 Can be fully qualified, or simple, and simple defaults to `androidx.test.espresso.matcher` package
4478 (e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers`
@@ -62,15 +96,15 @@ def find_element_by_android_data_matcher(
6296 )
6397
6498 def find_elements_by_android_data_matcher (
65- self , name : Optional [str ] = None , args : Optional [str ] = None , className : Optional [str ] = None ) -> List ['WebElement' ]:
99+ self , name : Optional [str ] = None , args : Optional [Any ] = None , className : Optional [str ] = None ) -> List ['WebElement' ]:
66100 """Finds elements by [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
67101 It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
68102
69103 Args:
70104 name (:obj:`str`, optional): The name of a method to invoke.
71105 The method must return a Hamcrest
72106 [Matcher](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html)
73- args (:obj:`str `, optional): The args provided to the method
107+ args (:obj:`Any `, optional): The args provided to the method
74108 className (:obj:`str`, optional): The class name that the method is part of (defaults to `org.hamcrest.Matchers`).
75109 Can be fully qualified, or simple, and simple defaults to `androidx.test.espresso.matcher` package
76110 (e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers`
@@ -89,7 +123,7 @@ def find_elements_by_android_data_matcher(
89123 value = self ._build_data_matcher (name = name , args = args , className = className )
90124 )
91125
92- def _build_data_matcher (self , name : Optional [str ] = None , args : Optional [str ]
126+ def _build_data_matcher (self , name : Optional [str ] = None , args : Optional [Any ]
93127 = None , className : Optional [str ] = None ) -> str :
94128 result = {}
95129
0 commit comments