15
15
# pylint: disable=abstract-method
16
16
17
17
import json
18
- from typing import TYPE_CHECKING , List , Optional
18
+ from typing import TYPE_CHECKING , Any , List , Optional
19
19
20
20
from appium .webdriver .common .mobileby import MobileBy
21
21
28
28
class AndroidSearchContext (BaseSearchContext ):
29
29
"""Define search context for Android"""
30
30
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
+
31
65
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' :
33
67
"""Finds element by [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
34
68
35
69
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
@@ -38,7 +72,7 @@ def find_element_by_android_data_matcher(
38
72
name (:obj:`str`, optional): The name of a method to invoke.
39
73
The method must return a Hamcrest
40
74
[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
42
76
className (:obj:`str`, optional): The class name that the method is part of (defaults to `org.hamcrest.Matchers`).
43
77
Can be fully qualified, or simple, and simple defaults to `androidx.test.espresso.matcher` package
44
78
(e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers`
@@ -62,15 +96,15 @@ def find_element_by_android_data_matcher(
62
96
)
63
97
64
98
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' ]:
66
100
"""Finds elements by [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
67
101
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
68
102
69
103
Args:
70
104
name (:obj:`str`, optional): The name of a method to invoke.
71
105
The method must return a Hamcrest
72
106
[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
74
108
className (:obj:`str`, optional): The class name that the method is part of (defaults to `org.hamcrest.Matchers`).
75
109
Can be fully qualified, or simple, and simple defaults to `androidx.test.espresso.matcher` package
76
110
(e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers`
@@ -89,7 +123,7 @@ def find_elements_by_android_data_matcher(
89
123
value = self ._build_data_matcher (name = name , args = args , className = className )
90
124
)
91
125
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 ]
93
127
= None , className : Optional [str ] = None ) -> str :
94
128
result = {}
95
129
0 commit comments