Skip to content

Commit b70422b

Browse files
authored
feat: add AppiumBy instead of MobileBy (appium#659)
* feat: add AppiumBy instead of MobileBy * add class description * use deprecated::
1 parent d7cb6b5 commit b70422b

22 files changed

+200
-160
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from selenium.webdriver.common.by import By
16+
17+
18+
class AppiumBy(By):
19+
IOS_PREDICATE = '-ios predicate string'
20+
IOS_UIAUTOMATION = '-ios uiautomation'
21+
IOS_CLASS_CHAIN = '-ios class chain'
22+
ANDROID_UIAUTOMATOR = '-android uiautomator'
23+
ANDROID_VIEWTAG = '-android viewtag'
24+
ANDROID_DATA_MATCHER = '-android datamatcher'
25+
ANDROID_VIEW_MATCHER = '-android viewmatcher'
26+
# Deprecated
27+
WINDOWS_UI_AUTOMATION = '-windows uiautomation'
28+
ACCESSIBILITY_ID = 'accessibility id'
29+
IMAGE = '-image'
30+
CUSTOM = '-custom'

appium/webdriver/common/mobileby.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,13 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from selenium.webdriver.common.by import By
15+
from appium.webdriver.common.appiumby import AppiumBy
1616

1717

18-
class MobileBy(By):
19-
IOS_PREDICATE = '-ios predicate string'
20-
IOS_UIAUTOMATION = '-ios uiautomation'
21-
IOS_CLASS_CHAIN = '-ios class chain'
22-
ANDROID_UIAUTOMATOR = '-android uiautomator'
23-
ANDROID_VIEWTAG = '-android viewtag'
24-
ANDROID_DATA_MATCHER = '-android datamatcher'
25-
ANDROID_VIEW_MATCHER = '-android viewmatcher'
26-
# Deprecated
27-
WINDOWS_UI_AUTOMATION = '-windows uiautomation'
28-
ACCESSIBILITY_ID = 'accessibility id'
29-
IMAGE = '-image'
30-
CUSTOM = '-custom'
18+
class MobileBy(AppiumBy):
19+
"""
20+
deprecated:: 2.1.0
21+
Please use 'from appium.webdriver.common.appiumby import AppiumBy' instead of 'MobileBy'.
22+
"""
23+
24+
pass

appium/webdriver/common/multi_action.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434

3535
class MultiAction:
3636
"""
37-
Deprecated.
38-
Please use W3C actions instead: http://appium.io/docs/en/commands/interactions/actions/
37+
deprecated:: 2.0.0
38+
Please use W3C actions instead: http://appium.io/docs/en/commands/interactions/actions/
3939
"""
4040

4141
def __init__(self, driver: 'WebDriver', element: Optional['WebElement'] = None) -> None:

appium/webdriver/common/touch_action.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838

3939
class TouchAction:
4040
"""
41-
Deprecated.
42-
Please use W3C actions instead: http://appium.io/docs/en/commands/interactions/actions/
41+
deprecated:: 2.0.0
42+
Please use W3C actions instead: http://appium.io/docs/en/commands/interactions/actions/
4343
"""
4444

4545
def __init__(self, driver: Optional['WebDriver'] = None):

appium/webdriver/extensions/search_context/android.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from typing import TYPE_CHECKING, Any, List, Optional, TypeVar, Union
1919

2020
from appium.common.logger import logger
21-
from appium.webdriver.common.mobileby import MobileBy
21+
from appium.webdriver.common.appiumby import AppiumBy
2222

2323
from .base_search_context import BaseSearchContext
2424

@@ -35,7 +35,8 @@ def find_element_by_android_view_matcher(
3535
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
3636
) -> 'WebElement':
3737
"""
38-
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEW_MATCHER' instead.
38+
deprecated:: 2.1.0
39+
Please use 'find_element' with 'AppiumBy.ANDROID_VIEW_MATCHER' instead.
3940
4041
Finds element by [onView](https://developer.android.com/training/testing/espresso/basics) in Android
4142
@@ -61,17 +62,18 @@ def find_element_by_android_view_matcher(
6162
driver.find_element_by_android_view_matcher(name='withText', args=['Accessibility'], className='ViewMatchers')
6263
"""
6364

64-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEW_MATCHER' instead.")
65+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEW_MATCHER' instead.")
6566

6667
return self.find_element(
67-
by=MobileBy.ANDROID_VIEW_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
68+
by=AppiumBy.ANDROID_VIEW_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
6869
)
6970

7071
def find_element_by_android_data_matcher(
7172
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
7273
) -> 'WebElement':
7374
"""
74-
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_DATA_MATCHER' instead.
75+
deprecated:: 2.1.0
76+
Please use 'find_element' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.
7577
7678
Finds element by
7779
[onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
@@ -98,17 +100,18 @@ def find_element_by_android_data_matcher(
98100
driver.find_element_by_android_data_matcher(name='hasEntry', args=['title', 'Animation'])
99101
"""
100102

101-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_DATA_MATCHER' instead.")
103+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.")
102104

103105
return self.find_element(
104-
by=MobileBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
106+
by=AppiumBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
105107
)
106108

107109
def find_elements_by_android_data_matcher(
108110
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
109111
) -> List['WebElement']:
110112
"""
111-
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_DATA_MATCHER' instead.
113+
deprecated:: 2.1.0
114+
Please use 'find_elements' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.
112115
113116
Finds elements by
114117
[onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
@@ -131,10 +134,10 @@ def find_elements_by_android_data_matcher(
131134
driver.find_elements_by_android_data_matcher(name='hasEntry', args=['title', 'Animation'])
132135
"""
133136

134-
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_DATA_MATCHER' instead.")
137+
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.")
135138

136139
return self.find_elements(
137-
by=MobileBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
140+
by=AppiumBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
138141
)
139142

140143
def _build_data_matcher(
@@ -150,7 +153,8 @@ def _build_data_matcher(
150153

151154
def find_element_by_android_uiautomator(self: T, uia_string: str) -> 'WebElement':
152155
"""
153-
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.
156+
deprecated:: 2.1.0
157+
Please use 'find_element' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.
154158
155159
Finds element by uiautomator in Android.
156160
@@ -164,13 +168,13 @@ def find_element_by_android_uiautomator(self: T, uia_string: str) -> 'WebElement
164168
`appium.webdriver.webelement.WebElement`: The found element
165169
"""
166170

167-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.")
171+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.")
168172

169-
return self.find_element(by=MobileBy.ANDROID_UIAUTOMATOR, value=uia_string)
173+
return self.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value=uia_string)
170174

171175
def find_elements_by_android_uiautomator(self: T, uia_string: str) -> List['WebElement']:
172176
"""
173-
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.
177+
[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.
174178
175179
Finds elements by uiautomator in Android.
176180
@@ -184,13 +188,14 @@ def find_elements_by_android_uiautomator(self: T, uia_string: str) -> List['WebE
184188
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
185189
"""
186190

187-
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.")
191+
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.")
188192

189-
return self.find_elements(by=MobileBy.ANDROID_UIAUTOMATOR, value=uia_string)
193+
return self.find_elements(by=AppiumBy.ANDROID_UIAUTOMATOR, value=uia_string)
190194

191195
def find_element_by_android_viewtag(self: T, tag: str) -> 'WebElement':
192196
"""
193-
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.
197+
deprecated:: 2.1.0
198+
Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.
194199
195200
Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.
196201
@@ -206,13 +211,14 @@ def find_element_by_android_viewtag(self: T, tag: str) -> 'WebElement':
206211
`appium.webdriver.webelement.WebElement`: The found element
207212
"""
208213

209-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.")
214+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.")
210215

211-
return self.find_element(by=MobileBy.ANDROID_VIEWTAG, value=tag)
216+
return self.find_element(by=AppiumBy.ANDROID_VIEWTAG, value=tag)
212217

213218
def find_elements_by_android_viewtag(self: T, tag: str) -> List['WebElement']:
214219
"""
215-
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_VIEWTAG' instead.
220+
deprecated:: 2.1.0
221+
Please use 'find_elements' with 'AppiumBy.ANDROID_VIEWTAG' instead.
216222
217223
Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.
218224
@@ -228,6 +234,6 @@ def find_elements_by_android_viewtag(self: T, tag: str) -> List['WebElement']:
228234
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
229235
"""
230236

231-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.")
237+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.")
232238

233-
return self.find_elements(by=MobileBy.ANDROID_VIEWTAG, value=tag)
239+
return self.find_elements(by=AppiumBy.ANDROID_VIEWTAG, value=tag)

appium/webdriver/extensions/search_context/custom.py

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

1919
from appium.common.logger import logger
20-
from appium.webdriver.common.mobileby import MobileBy
20+
from appium.webdriver.common.appiumby import AppiumBy
2121

2222
from .base_search_context import BaseSearchContext
2323

@@ -32,7 +32,8 @@ class CustomSearchContext(BaseSearchContext):
3232

3333
def find_element_by_custom(self: T, selector: str) -> 'WebElement':
3434
"""
35-
[Deprecated] Please use 'find_element' with 'MobileBy.CUSTOM' instead.
35+
deprecated:: 2.1.0
36+
Please use 'find_element' with 'AppiumBy.CUSTOM' instead.
3637
3738
Finds an element in conjunction with a custom element finding plugin
3839
@@ -50,13 +51,14 @@ def find_element_by_custom(self: T, selector: str) -> 'WebElement':
5051
5152
"""
5253

53-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.CUSTOM' instead.")
54+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.CUSTOM' instead.")
5455

55-
return self.find_element(by=MobileBy.CUSTOM, value=selector)
56+
return self.find_element(by=AppiumBy.CUSTOM, value=selector)
5657

5758
def find_elements_by_custom(self: T, selector: str) -> List['WebElement']:
5859
"""
59-
[Deprecated] Please use 'find_elements' with 'MobileBy.CUSTOM' instead.
60+
deprecated:: 2.1.0
61+
Please use 'find_elements' with 'AppiumBy.CUSTOM' instead.
6062
6163
Finds elements in conjunction with a custom element finding plugin
6264
@@ -73,6 +75,6 @@ def find_elements_by_custom(self: T, selector: str) -> List['WebElement']:
7375
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
7476
"""
7577

76-
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.CUSTOM' instead.")
78+
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.CUSTOM' instead.")
7779

78-
return self.find_elements(by=MobileBy.CUSTOM, value=selector)
80+
return self.find_elements(by=AppiumBy.CUSTOM, value=selector)

appium/webdriver/extensions/search_context/ios.py

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from typing import TYPE_CHECKING, List, TypeVar, Union
1818

1919
from appium.common.logger import logger
20-
from appium.webdriver.common.mobileby import MobileBy
20+
from appium.webdriver.common.appiumby import AppiumBy
2121

2222
from .base_search_context import BaseSearchContext
2323

@@ -32,7 +32,8 @@ class iOSSearchContext(BaseSearchContext):
3232

3333
def find_element_by_ios_uiautomation(self: T, uia_string: str) -> 'WebElement':
3434
"""
35-
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_UIAUTOMATION' instead.
35+
deprecated:: 2.1.0
36+
Please use 'find_element' with 'AppiumBy.IOS_UIAUTOMATION' instead.
3637
3738
Finds an element by uiautomation in iOS.
3839
@@ -47,13 +48,14 @@ def find_element_by_ios_uiautomation(self: T, uia_string: str) -> 'WebElement':
4748
4849
"""
4950

50-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_UIAUTOMATION' instead.")
51+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_UIAUTOMATION' instead.")
5152

52-
return self.find_element(by=MobileBy.IOS_UIAUTOMATION, value=uia_string)
53+
return self.find_element(by=AppiumBy.IOS_UIAUTOMATION, value=uia_string)
5354

5455
def find_elements_by_ios_uiautomation(self: T, uia_string: str) -> List['WebElement']:
5556
"""
56-
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_UIAUTOMATION' instead.
57+
deprecated:: 2.1.0
58+
Please use 'find_elements' with 'AppiumBy.IOS_UIAUTOMATION' instead.
5759
5860
Finds elements by uiautomation in iOS.
5961
@@ -68,13 +70,14 @@ def find_elements_by_ios_uiautomation(self: T, uia_string: str) -> List['WebElem
6870
6971
"""
7072

71-
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_UIAUTOMATION' instead.")
73+
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_UIAUTOMATION' instead.")
7274

73-
return self.find_elements(by=MobileBy.IOS_UIAUTOMATION, value=uia_string)
75+
return self.find_elements(by=AppiumBy.IOS_UIAUTOMATION, value=uia_string)
7476

7577
def find_element_by_ios_predicate(self: T, predicate_string: str) -> 'WebElement':
7678
"""
77-
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_PREDICATE' instead.
79+
deprecated:: 2.1.0
80+
Please use 'find_element' with 'AppiumBy.IOS_PREDICATE' instead.
7881
7982
Find an element by ios predicate string.
8083
@@ -89,13 +92,14 @@ def find_element_by_ios_predicate(self: T, predicate_string: str) -> 'WebElement
8992
9093
"""
9194

92-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_PREDICATE' instead.")
95+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_PREDICATE' instead.")
9396

94-
return self.find_element(by=MobileBy.IOS_PREDICATE, value=predicate_string)
97+
return self.find_element(by=AppiumBy.IOS_PREDICATE, value=predicate_string)
9598

9699
def find_elements_by_ios_predicate(self: T, predicate_string: str) -> List['WebElement']:
97100
"""
98-
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_PREDICATE' instead.
101+
deprecated:: 2.1.0
102+
Please use 'find_elements' with 'AppiumBy.IOS_PREDICATE' instead.
99103
100104
Finds elements by ios predicate string.
101105
@@ -109,13 +113,14 @@ def find_elements_by_ios_predicate(self: T, predicate_string: str) -> List['WebE
109113
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
110114
"""
111115

112-
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_PREDICATE' instead.")
116+
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_PREDICATE' instead.")
113117

114-
return self.find_elements(by=MobileBy.IOS_PREDICATE, value=predicate_string)
118+
return self.find_elements(by=AppiumBy.IOS_PREDICATE, value=predicate_string)
115119

116120
def find_element_by_ios_class_chain(self: T, class_chain_string: str) -> 'WebElement':
117121
"""
118-
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_CLASS_CHAIN' instead.
122+
deprecated:: 2.1.0
123+
Please use 'find_element' with 'AppiumBy.IOS_CLASS_CHAIN' instead.
119124
120125
Find an element by ios class chain string.
121126
@@ -129,13 +134,14 @@ def find_element_by_ios_class_chain(self: T, class_chain_string: str) -> 'WebEle
129134
`appium.webdriver.webelement.WebElement`: The found element
130135
"""
131136

132-
logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_CLASS_CHAIN' instead.")
137+
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_CLASS_CHAIN' instead.")
133138

134-
return self.find_element(by=MobileBy.IOS_CLASS_CHAIN, value=class_chain_string)
139+
return self.find_element(by=AppiumBy.IOS_CLASS_CHAIN, value=class_chain_string)
135140

136141
def find_elements_by_ios_class_chain(self: T, class_chain_string: str) -> List['WebElement']:
137142
"""
138-
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_CLASS_CHAIN' instead.
143+
deprecated:: 2.1.0
144+
Please use 'find_elements' with 'AppiumBy.IOS_CLASS_CHAIN' instead.
139145
140146
Finds elements by ios class chain string.
141147
@@ -149,6 +155,6 @@ def find_elements_by_ios_class_chain(self: T, class_chain_string: str) -> List['
149155
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
150156
"""
151157

152-
logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_CLASS_CHAIN' instead.")
158+
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_CLASS_CHAIN' instead.")
153159

154-
return self.find_elements(by=MobileBy.IOS_CLASS_CHAIN, value=class_chain_string)
160+
return self.find_elements(by=AppiumBy.IOS_CLASS_CHAIN, value=class_chain_string)

0 commit comments

Comments
 (0)