Skip to content

Commit d7cb6b5

Browse files
authored
chore: add deprecated mark for find_element_by* (#657)
1 parent ace98dc commit d7cb6b5

File tree

6 files changed

+145
-36
lines changed

6 files changed

+145
-36
lines changed

appium/webdriver/extensions/search_context/android.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import json
1818
from typing import TYPE_CHECKING, Any, List, Optional, TypeVar, Union
1919

20+
from appium.common.logger import logger
2021
from appium.webdriver.common.mobileby import MobileBy
2122

2223
from .base_search_context import BaseSearchContext
@@ -33,7 +34,10 @@ class AndroidSearchContext(BaseSearchContext):
3334
def find_element_by_android_view_matcher(
3435
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
3536
) -> 'WebElement':
36-
"""Finds element by [onView](https://developer.android.com/training/testing/espresso/basics) in Android
37+
"""
38+
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEW_MATCHER' instead.
39+
40+
Finds element by [onView](https://developer.android.com/training/testing/espresso/basics) in Android
3741
3842
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
3943
@@ -57,14 +61,19 @@ def find_element_by_android_view_matcher(
5761
driver.find_element_by_android_view_matcher(name='withText', args=['Accessibility'], className='ViewMatchers')
5862
"""
5963

64+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEW_MATCHER' instead.")
65+
6066
return self.find_element(
6167
by=MobileBy.ANDROID_VIEW_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
6268
)
6369

6470
def find_element_by_android_data_matcher(
6571
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
6672
) -> 'WebElement':
67-
"""Finds element by
73+
"""
74+
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_DATA_MATCHER' instead.
75+
76+
Finds element by
6877
[onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
6978
7079
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
@@ -89,14 +98,19 @@ def find_element_by_android_data_matcher(
8998
driver.find_element_by_android_data_matcher(name='hasEntry', args=['title', 'Animation'])
9099
"""
91100

101+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_DATA_MATCHER' instead.")
102+
92103
return self.find_element(
93104
by=MobileBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
94105
)
95106

96107
def find_elements_by_android_data_matcher(
97108
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
98109
) -> List['WebElement']:
99-
"""Finds elements by
110+
"""
111+
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_DATA_MATCHER' instead.
112+
113+
Finds elements by
100114
[onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
101115
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
102116
@@ -117,6 +131,8 @@ def find_elements_by_android_data_matcher(
117131
driver.find_elements_by_android_data_matcher(name='hasEntry', args=['title', 'Animation'])
118132
"""
119133

134+
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_DATA_MATCHER' instead.")
135+
120136
return self.find_elements(
121137
by=MobileBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
122138
)
@@ -133,7 +149,10 @@ def _build_data_matcher(
133149
return json.dumps(result)
134150

135151
def find_element_by_android_uiautomator(self: T, uia_string: str) -> 'WebElement':
136-
"""Finds element by uiautomator in Android.
152+
"""
153+
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.
154+
155+
Finds element by uiautomator in Android.
137156
138157
Args:
139158
uia_string: The element name in the Android UIAutomator library
@@ -144,10 +163,16 @@ def find_element_by_android_uiautomator(self: T, uia_string: str) -> 'WebElement
144163
Returns:
145164
`appium.webdriver.webelement.WebElement`: The found element
146165
"""
166+
167+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.")
168+
147169
return self.find_element(by=MobileBy.ANDROID_UIAUTOMATOR, value=uia_string)
148170

149171
def find_elements_by_android_uiautomator(self: T, uia_string: str) -> List['WebElement']:
150-
"""Finds elements by uiautomator in Android.
172+
"""
173+
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.
174+
175+
Finds elements by uiautomator in Android.
151176
152177
Args:
153178
uia_string: The element name in the Android UIAutomator library
@@ -158,10 +183,16 @@ def find_elements_by_android_uiautomator(self: T, uia_string: str) -> List['WebE
158183
Returns:
159184
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
160185
"""
186+
187+
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.")
188+
161189
return self.find_elements(by=MobileBy.ANDROID_UIAUTOMATOR, value=uia_string)
162190

163191
def find_element_by_android_viewtag(self: T, tag: str) -> 'WebElement':
164-
"""Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.
192+
"""
193+
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.
194+
195+
Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.
165196
166197
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
167198
@@ -174,10 +205,16 @@ def find_element_by_android_viewtag(self: T, tag: str) -> 'WebElement':
174205
Returns:
175206
`appium.webdriver.webelement.WebElement`: The found element
176207
"""
208+
209+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.")
210+
177211
return self.find_element(by=MobileBy.ANDROID_VIEWTAG, value=tag)
178212

179213
def find_elements_by_android_viewtag(self: T, tag: str) -> List['WebElement']:
180-
"""Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.
214+
"""
215+
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_VIEWTAG' instead.
216+
217+
Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.
181218
182219
It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver).
183220
@@ -190,4 +227,7 @@ def find_elements_by_android_viewtag(self: T, tag: str) -> List['WebElement']:
190227
Returns:
191228
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
192229
"""
230+
231+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.")
232+
193233
return self.find_elements(by=MobileBy.ANDROID_VIEWTAG, value=tag)

appium/webdriver/extensions/search_context/custom.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from typing import TYPE_CHECKING, List, TypeVar, Union
1818

19+
from appium.common.logger import logger
1920
from appium.webdriver.common.mobileby import MobileBy
2021

2122
from .base_search_context import BaseSearchContext
@@ -30,7 +31,10 @@ class CustomSearchContext(BaseSearchContext):
3031
"""Define search context for custom plugin"""
3132

3233
def find_element_by_custom(self: T, selector: str) -> 'WebElement':
33-
"""Finds an element in conjunction with a custom element finding plugin
34+
"""
35+
[Deprecated] Please use 'find_element' with 'MobileBy.CUSTOM' instead.
36+
37+
Finds an element in conjunction with a custom element finding plugin
3438
3539
Args:
3640
selector: a string of the form "module:selector", where "module" is
@@ -45,10 +49,16 @@ def find_element_by_custom(self: T, selector: str) -> 'WebElement':
4549
`appium.webdriver.webelement.WebElement`: The found element
4650
4751
"""
52+
53+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.CUSTOM' instead.")
54+
4855
return self.find_element(by=MobileBy.CUSTOM, value=selector)
4956

5057
def find_elements_by_custom(self: T, selector: str) -> List['WebElement']:
51-
"""Finds elements in conjunction with a custom element finding plugin
58+
"""
59+
[Deprecated] Please use 'find_elements' with 'MobileBy.CUSTOM' instead.
60+
61+
Finds elements in conjunction with a custom element finding plugin
5262
5363
Args:
5464
selector: a string of the form "module:selector", where "module" is
@@ -62,4 +72,7 @@ def find_elements_by_custom(self: T, selector: str) -> List['WebElement']:
6272
Returns:
6373
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
6474
"""
75+
76+
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.CUSTOM' instead.")
77+
6578
return self.find_elements(by=MobileBy.CUSTOM, value=selector)

appium/webdriver/extensions/search_context/ios.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from typing import TYPE_CHECKING, List, TypeVar, Union
1818

19+
from appium.common.logger import logger
1920
from appium.webdriver.common.mobileby import MobileBy
2021

2122
from .base_search_context import BaseSearchContext
@@ -30,7 +31,10 @@ class iOSSearchContext(BaseSearchContext):
3031
"""Define search context for iOS"""
3132

3233
def find_element_by_ios_uiautomation(self: T, uia_string: str) -> 'WebElement':
33-
"""Finds an element by uiautomation in iOS.
34+
"""
35+
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_UIAUTOMATION' instead.
36+
37+
Finds an element by uiautomation in iOS.
3438
3539
Args:
3640
uia_string: The element name in the iOS UIAutomation library
@@ -42,10 +46,16 @@ def find_element_by_ios_uiautomation(self: T, uia_string: str) -> 'WebElement':
4246
`appium.webdriver.webelement.WebElement`: The found element
4347
4448
"""
49+
50+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_UIAUTOMATION' instead.")
51+
4552
return self.find_element(by=MobileBy.IOS_UIAUTOMATION, value=uia_string)
4653

4754
def find_elements_by_ios_uiautomation(self: T, uia_string: str) -> List['WebElement']:
48-
"""Finds elements by uiautomation in iOS.
55+
"""
56+
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_UIAUTOMATION' instead.
57+
58+
Finds elements by uiautomation in iOS.
4959
5060
Args:
5161
uia_string: The element name in the iOS UIAutomation library
@@ -57,10 +67,16 @@ def find_elements_by_ios_uiautomation(self: T, uia_string: str) -> List['WebElem
5767
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
5868
5969
"""
70+
71+
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_UIAUTOMATION' instead.")
72+
6073
return self.find_elements(by=MobileBy.IOS_UIAUTOMATION, value=uia_string)
6174

6275
def find_element_by_ios_predicate(self: T, predicate_string: str) -> 'WebElement':
63-
"""Find an element by ios predicate string.
76+
"""
77+
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_PREDICATE' instead.
78+
79+
Find an element by ios predicate string.
6480
6581
Args:
6682
predicate_string: The predicate string
@@ -72,10 +88,16 @@ def find_element_by_ios_predicate(self: T, predicate_string: str) -> 'WebElement
7288
`appium.webdriver.webelement.WebElement`: The found element
7389
7490
"""
91+
92+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_PREDICATE' instead.")
93+
7594
return self.find_element(by=MobileBy.IOS_PREDICATE, value=predicate_string)
7695

7796
def find_elements_by_ios_predicate(self: T, predicate_string: str) -> List['WebElement']:
78-
"""Finds elements by ios predicate string.
97+
"""
98+
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_PREDICATE' instead.
99+
100+
Finds elements by ios predicate string.
79101
80102
Args:
81103
predicate_string: The predicate string
@@ -86,10 +108,16 @@ def find_elements_by_ios_predicate(self: T, predicate_string: str) -> List['WebE
86108
Returns:
87109
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
88110
"""
111+
112+
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_PREDICATE' instead.")
113+
89114
return self.find_elements(by=MobileBy.IOS_PREDICATE, value=predicate_string)
90115

91116
def find_element_by_ios_class_chain(self: T, class_chain_string: str) -> 'WebElement':
92-
"""Find an element by ios class chain string.
117+
"""
118+
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_CLASS_CHAIN' instead.
119+
120+
Find an element by ios class chain string.
93121
94122
Args:
95123
class_chain_string: The class chain string
@@ -100,10 +128,16 @@ def find_element_by_ios_class_chain(self: T, class_chain_string: str) -> 'WebEle
100128
Returns:
101129
`appium.webdriver.webelement.WebElement`: The found element
102130
"""
131+
132+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_CLASS_CHAIN' instead.")
133+
103134
return self.find_element(by=MobileBy.IOS_CLASS_CHAIN, value=class_chain_string)
104135

105136
def find_elements_by_ios_class_chain(self: T, class_chain_string: str) -> List['WebElement']:
106-
"""Finds elements by ios class chain string.
137+
"""
138+
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_CLASS_CHAIN' instead.
139+
140+
Finds elements by ios class chain string.
107141
108142
Args:
109143
class_chain_string: The class chain string
@@ -114,4 +148,7 @@ def find_elements_by_ios_class_chain(self: T, class_chain_string: str) -> List['
114148
Returns:
115149
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
116150
"""
151+
152+
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_CLASS_CHAIN' instead.")
153+
117154
return self.find_elements(by=MobileBy.IOS_CLASS_CHAIN, value=class_chain_string)

appium/webdriver/extensions/search_context/mobile.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import base64
1818
from typing import TYPE_CHECKING, List, TypeVar, Union
1919

20+
from appium.common.logger import logger
2021
from appium.webdriver.common.mobileby import MobileBy
2122

2223
from .base_search_context import BaseSearchContext
@@ -31,7 +32,10 @@ class MobileSearchContext(BaseSearchContext):
3132
"""Define search context for Mobile(Android, iOS)"""
3233

3334
def find_element_by_accessibility_id(self: T, accessibility_id: str) -> 'WebElement':
34-
"""Finds an element by accessibility id.
35+
"""
36+
[Deprecated] Please use 'find_element' with 'MobileBy.ACCESSIBILITY_ID' instead.
37+
38+
Finds an element by accessibility id.
3539
3640
Args:
3741
accessibility_id: A string corresponding to a recursive element search using the
@@ -44,10 +48,16 @@ def find_element_by_accessibility_id(self: T, accessibility_id: str) -> 'WebElem
4448
`appium.webdriver.webelement.WebElement`: The found element
4549
4650
"""
51+
52+
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ACCESSIBILITY_ID' instead.")
53+
4754
return self.find_element(by=MobileBy.ACCESSIBILITY_ID, value=accessibility_id)
4855

4956
def find_elements_by_accessibility_id(self: T, accessibility_id: str) -> List['WebElement']:
50-
"""Finds elements by accessibility id.
57+
"""
58+
[Deprecated] Please use 'find_elements' with 'MobileBy.ACCESSIBILITY_ID' instead.
59+
60+
Finds elements by accessibility id.
5161
5262
Args:
5363
accessibility_id: a string corresponding to a recursive element search using the
@@ -60,6 +70,9 @@ def find_elements_by_accessibility_id(self: T, accessibility_id: str) -> List['W
6070
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
6171
6272
"""
73+
74+
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.ACCESSIBILITY_ID' instead.")
75+
6376
return self.find_elements(by=MobileBy.ACCESSIBILITY_ID, value=accessibility_id)
6477

6578
def find_element_by_image(self: T, img_path: str) -> 'WebElement':
@@ -73,6 +86,7 @@ def find_element_by_image(self: T, img_path: str) -> 'WebElement':
7386
Returns:
7487
`appium.webdriver.webelement.WebElement`: The found element
7588
"""
89+
7690
with open(img_path, 'rb') as i_file:
7791
b64_data = base64.b64encode(i_file.read()).decode('UTF-8')
7892

0 commit comments

Comments
 (0)