Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add AppiumBy instead of MobileBy #659

Merged
merged 3 commits into from
Nov 26, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions appium/webdriver/common/appiumby.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from selenium.webdriver.common.by import By


class AppiumBy(By):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer it to not be a breaking change. E.g. keep the MobileBy strategy, but simply mark it as deprecated
AppiumBy may then be inherited from MobileBy to avoid unnecessary duplication.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MobileBy.ID in appium/webdriver/common/mobileby.py (inherits AppiumBy) etc are str. AppiumBy.ID also str. So basically both ID are set as id to find_element, for example.
I think they do not have breaking change... something wrong?

Yea, I was finding the way to print deprecation message when MobileBy.ID was called or when MobileBy.ID was given in find_element. But it was simply str.
So currently I've put the deprecation message in the module description.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mm, the deprecation package also does not work for str of class variables?

Yea, I think only documentation can mention it.

IOS_PREDICATE = '-ios predicate string'
IOS_UIAUTOMATION = '-ios uiautomation'
IOS_CLASS_CHAIN = '-ios class chain'
ANDROID_UIAUTOMATOR = '-android uiautomator'
ANDROID_VIEWTAG = '-android viewtag'
ANDROID_DATA_MATCHER = '-android datamatcher'
ANDROID_VIEW_MATCHER = '-android viewmatcher'
# Deprecated
WINDOWS_UI_AUTOMATION = '-windows uiautomation'
ACCESSIBILITY_ID = 'accessibility id'
IMAGE = '-image'
CUSTOM = '-custom'
21 changes: 7 additions & 14 deletions appium/webdriver/common/mobileby.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from selenium.webdriver.common.by import By
from appium.webdriver.common.appiumby import AppiumBy


class MobileBy(By):
IOS_PREDICATE = '-ios predicate string'
IOS_UIAUTOMATION = '-ios uiautomation'
IOS_CLASS_CHAIN = '-ios class chain'
ANDROID_UIAUTOMATOR = '-android uiautomator'
ANDROID_VIEWTAG = '-android viewtag'
ANDROID_DATA_MATCHER = '-android datamatcher'
ANDROID_VIEW_MATCHER = '-android viewmatcher'
# Deprecated
WINDOWS_UI_AUTOMATION = '-windows uiautomation'
ACCESSIBILITY_ID = 'accessibility id'
IMAGE = '-image'
CUSTOM = '-custom'
class MobileBy(AppiumBy):
"""
[Deprecated] Please use 'from appium.webdriver.common.appiumby import AppiumBy' instead of 'MobileBy'.
"""

pass
44 changes: 22 additions & 22 deletions appium/webdriver/extensions/search_context/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from typing import TYPE_CHECKING, Any, List, Optional, TypeVar, Union

from appium.common.logger import logger
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.appiumby import AppiumBy

from .base_search_context import BaseSearchContext

Expand All @@ -35,7 +35,7 @@ def find_element_by_android_view_matcher(
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEW_MATCHER' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEW_MATCHER' instead.

Finds element by [onView](https://developer.android.com/training/testing/espresso/basics) in Android

Expand All @@ -61,17 +61,17 @@ def find_element_by_android_view_matcher(
driver.find_element_by_android_view_matcher(name='withText', args=['Accessibility'], className='ViewMatchers')
"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEW_MATCHER' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEW_MATCHER' instead.")

return self.find_element(
by=MobileBy.ANDROID_VIEW_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
by=AppiumBy.ANDROID_VIEW_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
)

def find_element_by_android_data_matcher(
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_DATA_MATCHER' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.

Finds element by
[onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
Expand All @@ -98,17 +98,17 @@ def find_element_by_android_data_matcher(
driver.find_element_by_android_data_matcher(name='hasEntry', args=['title', 'Animation'])
"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_DATA_MATCHER' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.")

return self.find_element(
by=MobileBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
by=AppiumBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
)

def find_elements_by_android_data_matcher(
self: T, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None
) -> List['WebElement']:
"""
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_DATA_MATCHER' instead.
[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.

Finds elements by
[onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android
Expand All @@ -131,10 +131,10 @@ def find_elements_by_android_data_matcher(
driver.find_elements_by_android_data_matcher(name='hasEntry', args=['title', 'Animation'])
"""

logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_DATA_MATCHER' instead.")
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.")

return self.find_elements(
by=MobileBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
by=AppiumBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className)
)

def _build_data_matcher(
Expand All @@ -150,7 +150,7 @@ def _build_data_matcher(

def find_element_by_android_uiautomator(self: T, uia_string: str) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.

Finds element by uiautomator in Android.

Expand All @@ -164,13 +164,13 @@ def find_element_by_android_uiautomator(self: T, uia_string: str) -> 'WebElement
`appium.webdriver.webelement.WebElement`: The found element
"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.")

return self.find_element(by=MobileBy.ANDROID_UIAUTOMATOR, value=uia_string)
return self.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value=uia_string)

def find_elements_by_android_uiautomator(self: T, uia_string: str) -> List['WebElement']:
"""
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.
[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.

Finds elements by uiautomator in Android.

Expand All @@ -184,13 +184,13 @@ def find_elements_by_android_uiautomator(self: T, uia_string: str) -> List['WebE
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
"""

logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_UIAUTOMATOR' instead.")
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.")

return self.find_elements(by=MobileBy.ANDROID_UIAUTOMATOR, value=uia_string)
return self.find_elements(by=AppiumBy.ANDROID_UIAUTOMATOR, value=uia_string)

def find_element_by_android_viewtag(self: T, tag: str) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.

Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.

Expand All @@ -206,13 +206,13 @@ def find_element_by_android_viewtag(self: T, tag: str) -> 'WebElement':
`appium.webdriver.webelement.WebElement`: The found element
"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.")

return self.find_element(by=MobileBy.ANDROID_VIEWTAG, value=tag)
return self.find_element(by=AppiumBy.ANDROID_VIEWTAG, value=tag)

def find_elements_by_android_viewtag(self: T, tag: str) -> List['WebElement']:
"""
[Deprecated] Please use 'find_elements' with 'MobileBy.ANDROID_VIEWTAG' instead.
[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_VIEWTAG' instead.

Finds element by [View#tags](https://developer.android.com/reference/android/view/View#tags) in Android.

Expand All @@ -228,6 +228,6 @@ def find_elements_by_android_viewtag(self: T, tag: str) -> List['WebElement']:
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.ANDROID_VIEWTAG' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.")

return self.find_elements(by=MobileBy.ANDROID_VIEWTAG, value=tag)
return self.find_elements(by=AppiumBy.ANDROID_VIEWTAG, value=tag)
14 changes: 7 additions & 7 deletions appium/webdriver/extensions/search_context/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import TYPE_CHECKING, List, TypeVar, Union

from appium.common.logger import logger
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.appiumby import AppiumBy

from .base_search_context import BaseSearchContext

Expand All @@ -32,7 +32,7 @@ class CustomSearchContext(BaseSearchContext):

def find_element_by_custom(self: T, selector: str) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.CUSTOM' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.CUSTOM' instead.

Finds an element in conjunction with a custom element finding plugin

Expand All @@ -50,13 +50,13 @@ def find_element_by_custom(self: T, selector: str) -> 'WebElement':

"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.CUSTOM' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.CUSTOM' instead.")

return self.find_element(by=MobileBy.CUSTOM, value=selector)
return self.find_element(by=AppiumBy.CUSTOM, value=selector)

def find_elements_by_custom(self: T, selector: str) -> List['WebElement']:
"""
[Deprecated] Please use 'find_elements' with 'MobileBy.CUSTOM' instead.
[Deprecated] Please use 'find_elements' with 'AppiumBy.CUSTOM' instead.

Finds elements in conjunction with a custom element finding plugin

Expand All @@ -73,6 +73,6 @@ def find_elements_by_custom(self: T, selector: str) -> List['WebElement']:
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
"""

logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.CUSTOM' instead.")
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.CUSTOM' instead.")

return self.find_elements(by=MobileBy.CUSTOM, value=selector)
return self.find_elements(by=AppiumBy.CUSTOM, value=selector)
38 changes: 19 additions & 19 deletions appium/webdriver/extensions/search_context/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from typing import TYPE_CHECKING, List, TypeVar, Union

from appium.common.logger import logger
from appium.webdriver.common.mobileby import MobileBy
from appium.webdriver.common.appiumby import AppiumBy

from .base_search_context import BaseSearchContext

Expand All @@ -32,7 +32,7 @@ class iOSSearchContext(BaseSearchContext):

def find_element_by_ios_uiautomation(self: T, uia_string: str) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_UIAUTOMATION' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_UIAUTOMATION' instead.

Finds an element by uiautomation in iOS.

Expand All @@ -47,13 +47,13 @@ def find_element_by_ios_uiautomation(self: T, uia_string: str) -> 'WebElement':

"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_UIAUTOMATION' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_UIAUTOMATION' instead.")

return self.find_element(by=MobileBy.IOS_UIAUTOMATION, value=uia_string)
return self.find_element(by=AppiumBy.IOS_UIAUTOMATION, value=uia_string)

def find_elements_by_ios_uiautomation(self: T, uia_string: str) -> List['WebElement']:
"""
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_UIAUTOMATION' instead.
[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_UIAUTOMATION' instead.

Finds elements by uiautomation in iOS.

Expand All @@ -68,13 +68,13 @@ def find_elements_by_ios_uiautomation(self: T, uia_string: str) -> List['WebElem

"""

logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_UIAUTOMATION' instead.")
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_UIAUTOMATION' instead.")

return self.find_elements(by=MobileBy.IOS_UIAUTOMATION, value=uia_string)
return self.find_elements(by=AppiumBy.IOS_UIAUTOMATION, value=uia_string)

def find_element_by_ios_predicate(self: T, predicate_string: str) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_PREDICATE' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_PREDICATE' instead.

Find an element by ios predicate string.

Expand All @@ -89,13 +89,13 @@ def find_element_by_ios_predicate(self: T, predicate_string: str) -> 'WebElement

"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_PREDICATE' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_PREDICATE' instead.")

return self.find_element(by=MobileBy.IOS_PREDICATE, value=predicate_string)
return self.find_element(by=AppiumBy.IOS_PREDICATE, value=predicate_string)

def find_elements_by_ios_predicate(self: T, predicate_string: str) -> List['WebElement']:
"""
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_PREDICATE' instead.
[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_PREDICATE' instead.

Finds elements by ios predicate string.

Expand All @@ -109,13 +109,13 @@ def find_elements_by_ios_predicate(self: T, predicate_string: str) -> List['WebE
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
"""

logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_PREDICATE' instead.")
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_PREDICATE' instead.")

return self.find_elements(by=MobileBy.IOS_PREDICATE, value=predicate_string)
return self.find_elements(by=AppiumBy.IOS_PREDICATE, value=predicate_string)

def find_element_by_ios_class_chain(self: T, class_chain_string: str) -> 'WebElement':
"""
[Deprecated] Please use 'find_element' with 'MobileBy.IOS_CLASS_CHAIN' instead.
[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_CLASS_CHAIN' instead.

Find an element by ios class chain string.

Expand All @@ -129,13 +129,13 @@ def find_element_by_ios_class_chain(self: T, class_chain_string: str) -> 'WebEle
`appium.webdriver.webelement.WebElement`: The found element
"""

logger.warning("[Deprecated] Please use 'find_element' with 'MobileBy.IOS_CLASS_CHAIN' instead.")
logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_CLASS_CHAIN' instead.")

return self.find_element(by=MobileBy.IOS_CLASS_CHAIN, value=class_chain_string)
return self.find_element(by=AppiumBy.IOS_CLASS_CHAIN, value=class_chain_string)

def find_elements_by_ios_class_chain(self: T, class_chain_string: str) -> List['WebElement']:
"""
[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_CLASS_CHAIN' instead.
[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_CLASS_CHAIN' instead.

Finds elements by ios class chain string.

Expand All @@ -149,6 +149,6 @@ def find_elements_by_ios_class_chain(self: T, class_chain_string: str) -> List['
:obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements
"""

logger.warning("[Deprecated] Please use 'find_elements' with 'MobileBy.IOS_CLASS_CHAIN' instead.")
logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_CLASS_CHAIN' instead.")

return self.find_elements(by=MobileBy.IOS_CLASS_CHAIN, value=class_chain_string)
return self.find_elements(by=AppiumBy.IOS_CLASS_CHAIN, value=class_chain_string)
Loading