From d1dcd63a53f68c6cea1e05ec2c19b28d676d09c0 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sat, 25 Jun 2022 08:10:09 +0200 Subject: [PATCH 1/2] refactor: Remove previously deprecated methods and mark reset/close/launch APIs as deprecated --- appium/webdriver/common/multi_action.py | 6 +- appium/webdriver/common/touch_action.py | 6 +- appium/webdriver/extensions/applications.py | 23 +- .../extensions/search_context/__init__.py | 39 --- .../extensions/search_context/android.py | 237 ------------------ .../extensions/search_context/custom.py | 75 ------ .../extensions/search_context/ios.py | 155 ------------ .../extensions/search_context/mobile.py | 107 -------- .../extensions/search_context/windows.py | 61 ----- appium/webdriver/webdriver.py | 2 - .../search_context/find_by_image_tests.py | 3 - .../webdriver/search_context/android_test.py | 6 +- 12 files changed, 34 insertions(+), 686 deletions(-) delete mode 100644 appium/webdriver/extensions/search_context/__init__.py delete mode 100644 appium/webdriver/extensions/search_context/android.py delete mode 100644 appium/webdriver/extensions/search_context/custom.py delete mode 100644 appium/webdriver/extensions/search_context/ios.py delete mode 100644 appium/webdriver/extensions/search_context/mobile.py delete mode 100644 appium/webdriver/extensions/search_context/windows.py diff --git a/appium/webdriver/common/multi_action.py b/appium/webdriver/common/multi_action.py index 818c63d61..e416e2cf1 100644 --- a/appium/webdriver/common/multi_action.py +++ b/appium/webdriver/common/multi_action.py @@ -19,9 +19,9 @@ # chaining as the spec requires. import copy +import warnings from typing import TYPE_CHECKING, Dict, List, Optional, Union -from appium.common.logger import logger from appium.webdriver.mobilecommand import MobileCommand as Command if TYPE_CHECKING: @@ -37,7 +37,9 @@ class MultiAction: """ def __init__(self, driver: 'WebDriver', element: Optional['WebElement'] = None) -> None: - logger.warning("[Deprecated] 'MultiAction' action is deprecated. Please use W3C actions instead.") + warnings.warn( + "[Deprecated] 'MultiAction' action is deprecated. Please use W3C actions instead.", DeprecationWarning + ) self._driver = driver self._element = element diff --git a/appium/webdriver/common/touch_action.py b/appium/webdriver/common/touch_action.py index ba36efff5..10060752c 100644 --- a/appium/webdriver/common/touch_action.py +++ b/appium/webdriver/common/touch_action.py @@ -24,9 +24,9 @@ # pylint: disable=no-self-use import copy +import warnings from typing import TYPE_CHECKING, Dict, List, Optional, Union -from appium.common.logger import logger from appium.webdriver.mobilecommand import MobileCommand as Command if TYPE_CHECKING: @@ -41,7 +41,9 @@ class TouchAction: """ def __init__(self, driver: Optional['WebDriver'] = None): - logger.warning("[Deprecated] 'TouchAction' action is deprecated. Please use W3C actions instead.") + warnings.warn( + "[Deprecated] 'TouchAction' action is deprecated. Please use W3C actions instead.", DeprecationWarning + ) self._driver = driver self._actions: List = [] diff --git a/appium/webdriver/extensions/applications.py b/appium/webdriver/extensions/applications.py index e545d77a0..537de6b62 100644 --- a/appium/webdriver/extensions/applications.py +++ b/appium/webdriver/extensions/applications.py @@ -11,7 +11,7 @@ # 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. - +import warnings from typing import TYPE_CHECKING, Any, Dict from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands @@ -106,20 +106,34 @@ def remove_app(self, app_id: str, **options: Any) -> 'WebDriver': def launch_app(self) -> 'WebDriver': """Start on the device the application specified in the desired capabilities. + deprecated:: 2.0.0 Returns: Union['WebDriver', 'Applications']: Self instance """ + warnings.warn( + 'The "launchApp" API is deprecated and will be removed in future versions. ' + 'See https://github.com/appium/appium/issues/15807', + DeprecationWarning, + ) + self.execute(Command.LAUNCH_APP) return self # type: ignore def close_app(self) -> 'WebDriver': """Stop the running application, specified in the desired capabilities, on the device. + deprecated:: 2.0.0 Returns: Union['WebDriver', 'Applications']: Self instance """ + warnings.warn( + 'The "closeApp" API is deprecated and will be removed in future versions. ' + 'See https://github.com/appium/appium/issues/15807', + DeprecationWarning, + ) + self.execute(Command.CLOSE_APP) return self # type: ignore @@ -194,10 +208,17 @@ def app_strings(self, language: str = None, string_file: str = None) -> Dict[str def reset(self) -> 'WebDriver': """Resets the current application on the device. + deprecated:: 2.0.0 Returns: Union['WebDriver', 'Applications']: Self instance """ + warnings.warn( + 'The "reset" API is deprecated and will be removed in future versions. ' + 'See https://github.com/appium/appium/issues/15807', + DeprecationWarning, + ) + self.execute(Command.RESET) return self # type: ignore diff --git a/appium/webdriver/extensions/search_context/__init__.py b/appium/webdriver/extensions/search_context/__init__.py deleted file mode 100644 index ed9ad3ece..000000000 --- a/appium/webdriver/extensions/search_context/__init__.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/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 .android import AndroidSearchContext -from .custom import CustomSearchContext -from .ios import iOSSearchContext -from .mobile import MobileSearchContext -from .windows import WindowsSearchContext - - -class AppiumSearchContext( - AndroidSearchContext, - CustomSearchContext, - iOSSearchContext, - MobileSearchContext, - WindowsSearchContext, -): - """Returns appium driver search context""" - - -class AppiumWebElementSearchContext( - AndroidSearchContext, - CustomSearchContext, - iOSSearchContext, - MobileSearchContext, - WindowsSearchContext, -): - """Returns appium web element search context""" diff --git a/appium/webdriver/extensions/search_context/android.py b/appium/webdriver/extensions/search_context/android.py deleted file mode 100644 index 7aea8219a..000000000 --- a/appium/webdriver/extensions/search_context/android.py +++ /dev/null @@ -1,237 +0,0 @@ -#!/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. - -import json -from typing import TYPE_CHECKING, Any, List, Optional - -from appium.common.logger import logger -from appium.protocols.webdriver.can_find_elements import CanFindElements -from appium.webdriver.common.appiumby import AppiumBy - -if TYPE_CHECKING: - from appium.webdriver.webelement import WebElement - - -# noinspection PyPep8Naming -class AndroidSearchContext(CanFindElements): - """Define search context for Android""" - - def find_element_by_android_view_matcher( - self, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None - ) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.ANDROID_VIEW_MATCHER' instead. - - Finds element by [onView](https://developer.android.com/training/testing/espresso/basics) in Android - - It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). - - Args: - name: The name of a method to invoke. - The method must return a Hamcrest - [Matcher](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) - args: The args provided to the method - className: The class name that the method is part of (defaults to `org.hamcrest.Matchers`). - Can be fully qualified by having the androidx.test.espresso.matcher. prefix. - If the prefix is not provided then it is going to be added implicitly. - (e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers` - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - - Raises: - TypeError - Raises a TypeError if the arguments are not validated for JSON format - - Usage: - driver.find_element_by_android_view_matcher( - name='withText', args=['Accessibility'], className='ViewMatchers' - ) - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEW_MATCHER' instead.") - - return self.find_element( - by=AppiumBy.ANDROID_VIEW_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className) - ) - - def find_element_by_android_data_matcher( - self, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None - ) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.ANDROID_DATA_MATCHER' instead. - - Finds element by - [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android - - It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). - - Args: - name: The name of a method to invoke. - The method must return a Hamcrest - [Matcher](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) - args: The args provided to the method - className: The class name that the method is part of - (defaults to `org.hamcrest.Matchers`). - Can be fully qualified, or simple, and simple defaults to `androidx.test.espresso.matcher` package - (e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers` - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - - Raises: - TypeError - Raises a TypeError if the arguments are not validated for JSON format - - Usage: - driver.find_element_by_android_data_matcher(name='hasEntry', args=['title', 'Animation']) - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.") - - return self.find_element( - by=AppiumBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className) - ) - - def find_elements_by_android_data_matcher( - self, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None - ) -> List['WebElement']: - """ - deprecated:: 2.1.0 - Please use 'find_elements' with 'AppiumBy.ANDROID_DATA_MATCHER' instead. - - Finds elements by - [onData](https://medium.com/androiddevelopers/adapterviews-and-espresso-f4172aa853cf) in Android - It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). - - Args: - name: The name of a method to invoke. - The method must return a Hamcrest - [Matcher](http://hamcrest.org/JavaHamcrest/javadoc/1.3/org/hamcrest/Matcher.html) - args: The args provided to the method - className: The class name that the method is part of - (defaults to `org.hamcrest.Matchers`). - Can be fully qualified, or simple, and simple defaults to `androidx.test.espresso.matcher` package - (e.g.: `class=CursorMatchers` fully qualified is `class=androidx.test.espresso.matcher.CursorMatchers` - - Returns: - `appium.webdriver.webelement.WebElement`: The found elements - - Usage: - driver.find_elements_by_android_data_matcher(name='hasEntry', args=['title', 'Animation']) - """ - - logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_DATA_MATCHER' instead.") - - return self.find_elements( - by=AppiumBy.ANDROID_DATA_MATCHER, value=self._build_data_matcher(name=name, args=args, className=className) - ) - - def _build_data_matcher( - self, name: Optional[str] = None, args: Optional[Any] = None, className: Optional[str] = None - ) -> str: - result = {} - - for key, value in {'name': name, 'args': args, 'class': className}.items(): - if value is not None: - result[key] = value - - return json.dumps(result) - - def find_element_by_android_uiautomator(self, uia_string: str) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead. - - Finds element by uiautomator in Android. - - Args: - uia_string: The element name in the Android UIAutomator library - - Usage: - driver.find_element_by_android_uiautomator('.elements()[1].cells()[2]') - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.") - - return self.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value=uia_string) - - def find_elements_by_android_uiautomator(self, uia_string: str) -> List['WebElement']: - """ - [Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead. - - Finds elements by uiautomator in Android. - - Args: - uia_string: The element name in the Android UIAutomator library - - Usage: - driver.find_elements_by_android_uiautomator('.elements()[1].cells()[2]') - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - """ - - logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.ANDROID_UIAUTOMATOR' instead.") - - return self.find_elements(by=AppiumBy.ANDROID_UIAUTOMATOR, value=uia_string) - - def find_element_by_android_viewtag(self, tag: str) -> 'WebElement': - """ - deprecated:: 2.1.0 - 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. - - It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). - - Args: - tag: The tag name of the view to look for - - Usage: - driver.find_element_by_android_viewtag('a tag name') - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.") - - return self.find_element(by=AppiumBy.ANDROID_VIEWTAG, value=tag) - - def find_elements_by_android_viewtag(self, tag: str) -> List['WebElement']: - """ - deprecated:: 2.1.0 - 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. - - It works with [Espresso Driver](https://github.com/appium/appium-espresso-driver). - - Args: - tag: The tag name of the view to look for - - Usage: - driver.find_elements_by_android_viewtag('a tag name') - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ANDROID_VIEWTAG' instead.") - - return self.find_elements(by=AppiumBy.ANDROID_VIEWTAG, value=tag) diff --git a/appium/webdriver/extensions/search_context/custom.py b/appium/webdriver/extensions/search_context/custom.py deleted file mode 100644 index 93ba82d37..000000000 --- a/appium/webdriver/extensions/search_context/custom.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/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 typing import TYPE_CHECKING, List - -from appium.common.logger import logger -from appium.protocols.webdriver.can_find_elements import CanFindElements -from appium.webdriver.common.appiumby import AppiumBy - -if TYPE_CHECKING: - from appium.webdriver.webelement import WebElement - - -class CustomSearchContext(CanFindElements): - """Define search context for custom plugin""" - - def find_element_by_custom(self, selector: str) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.CUSTOM' instead. - - Finds an element in conjunction with a custom element finding plugin - - Args: - selector: a string of the form "module:selector", where "module" is - the shortcut name given in the customFindModules capability, and - "selector" is the string that will be passed to the custom element - finding plugin itself - - Usage: - driver.find_element_by_custom("foo:bar") - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.CUSTOM' instead.") - - return self.find_element(by=AppiumBy.CUSTOM, value=selector) - - def find_elements_by_custom(self, selector: str) -> List['WebElement']: - """ - deprecated:: 2.1.0 - Please use 'find_elements' with 'AppiumBy.CUSTOM' instead. - - Finds elements in conjunction with a custom element finding plugin - - Args: - selector: a string of the form "module:selector", where "module" is - the shortcut name given in the customFindModules capability, and - "selector" is the string that will be passed to the custom element - finding plugin itself - - Usage: - driver.find_elements_by_custom("foo:bar") - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - """ - - logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.CUSTOM' instead.") - - return self.find_elements(by=AppiumBy.CUSTOM, value=selector) diff --git a/appium/webdriver/extensions/search_context/ios.py b/appium/webdriver/extensions/search_context/ios.py deleted file mode 100644 index eef6c4e2b..000000000 --- a/appium/webdriver/extensions/search_context/ios.py +++ /dev/null @@ -1,155 +0,0 @@ -#!/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 typing import TYPE_CHECKING, List - -from appium.common.logger import logger -from appium.protocols.webdriver.can_find_elements import CanFindElements -from appium.webdriver.common.appiumby import AppiumBy - -if TYPE_CHECKING: - from appium.webdriver.webelement import WebElement - - -class iOSSearchContext(CanFindElements): - """Define search context for iOS""" - - def find_element_by_ios_uiautomation(self, uia_string: str) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.IOS_UIAUTOMATION' instead. - - Finds an element by uiautomation in iOS. - - Args: - uia_string: The element name in the iOS UIAutomation library - - Usage: - driver.find_element_by_ios_uiautomation('.elements()[1].cells()[2]') - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_UIAUTOMATION' instead.") - - return self.find_element(by=AppiumBy.IOS_UIAUTOMATION, value=uia_string) - - def find_elements_by_ios_uiautomation(self, uia_string: str) -> List['WebElement']: - """ - deprecated:: 2.1.0 - Please use 'find_elements' with 'AppiumBy.IOS_UIAUTOMATION' instead. - - Finds elements by uiautomation in iOS. - - Args: - uia_string: The element name in the iOS UIAutomation library - - Usage: - driver.find_elements_by_ios_uiautomation('.elements()[1].cells()[2]') - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - - """ - - logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_UIAUTOMATION' instead.") - - return self.find_elements(by=AppiumBy.IOS_UIAUTOMATION, value=uia_string) - - def find_element_by_ios_predicate(self, predicate_string: str) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.IOS_PREDICATE' instead. - - Find an element by ios predicate string. - - Args: - predicate_string: The predicate string - - Usage: - driver.find_element_by_ios_predicate('label == "myLabel"') - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_PREDICATE' instead.") - - return self.find_element(by=AppiumBy.IOS_PREDICATE, value=predicate_string) - - def find_elements_by_ios_predicate(self, predicate_string: str) -> List['WebElement']: - """ - deprecated:: 2.1.0 - Please use 'find_elements' with 'AppiumBy.IOS_PREDICATE' instead. - - Finds elements by ios predicate string. - - Args: - predicate_string: The predicate string - - Usage: - driver.find_elements_by_ios_predicate('label == "myLabel"') - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - """ - - logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_PREDICATE' instead.") - - return self.find_elements(by=AppiumBy.IOS_PREDICATE, value=predicate_string) - - def find_element_by_ios_class_chain(self, class_chain_string: str) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.IOS_CLASS_CHAIN' instead. - - Find an element by ios class chain string. - - Args: - class_chain_string: The class chain string - - Usage: - driver.find_element_by_ios_class_chain('XCUIElementTypeWindow/XCUIElementTypeButton[3]') - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.IOS_CLASS_CHAIN' instead.") - - return self.find_element(by=AppiumBy.IOS_CLASS_CHAIN, value=class_chain_string) - - def find_elements_by_ios_class_chain(self, class_chain_string: str) -> List['WebElement']: - """ - deprecated:: 2.1.0 - Please use 'find_elements' with 'AppiumBy.IOS_CLASS_CHAIN' instead. - - Finds elements by ios class chain string. - - Args: - class_chain_string: The class chain string - - Usage: - driver.find_elements_by_ios_class_chain('XCUIElementTypeWindow[2]/XCUIElementTypeAny[-2]') - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - """ - - logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.IOS_CLASS_CHAIN' instead.") - - return self.find_elements(by=AppiumBy.IOS_CLASS_CHAIN, value=class_chain_string) diff --git a/appium/webdriver/extensions/search_context/mobile.py b/appium/webdriver/extensions/search_context/mobile.py deleted file mode 100644 index 3518df2f6..000000000 --- a/appium/webdriver/extensions/search_context/mobile.py +++ /dev/null @@ -1,107 +0,0 @@ -#!/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. - -import base64 -from typing import TYPE_CHECKING, List - -from appium.common.logger import logger -from appium.protocols.webdriver.can_find_elements import CanFindElements -from appium.webdriver.common.appiumby import AppiumBy - -if TYPE_CHECKING: - from appium.webdriver.webelement import WebElement - - -class MobileSearchContext(CanFindElements): - """Define search context for Mobile(Android, iOS)""" - - def find_element_by_accessibility_id(self, accessibility_id: str) -> 'WebElement': - """ - deprecated:: 2.1.0 - Please use 'find_element' with 'AppiumBy.ACCESSIBILITY_ID' instead. - - Finds an element by accessibility id. - - Args: - accessibility_id: A string corresponding to a recursive element search using the - Id/Name that the native Accessibility options utilize - - Usage: - driver.find_element_by_accessibility_id() - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - - """ - - logger.warning("[Deprecated] Please use 'find_element' with 'AppiumBy.ACCESSIBILITY_ID' instead.") - - return self.find_element(by=AppiumBy.ACCESSIBILITY_ID, value=accessibility_id) - - def find_elements_by_accessibility_id(self, accessibility_id: str) -> List['WebElement']: - """ - deprecated:: 2.1.0 - Please use 'find_elements' with 'AppiumBy.ACCESSIBILITY_ID' instead. - - Finds elements by accessibility id. - - Args: - accessibility_id: a string corresponding to a recursive element search using the - Id/Name that the native Accessibility options utilize - - Usage: - driver.find_elements_by_accessibility_id() - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - - """ - - logger.warning("[Deprecated] Please use 'find_elements' with 'AppiumBy.ACCESSIBILITY_ID' instead.") - - return self.find_elements(by=AppiumBy.ACCESSIBILITY_ID, value=accessibility_id) - - def find_element_by_image(self, img_path: str) -> 'WebElement': - """Finds a portion of a screenshot by an image. - - Uses driver.find_image_occurrence under the hood. - - Args: - img_path: a string corresponding to the path of a image - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - """ - - with open(img_path, 'rb') as i_file: - b64_data = base64.b64encode(i_file.read()).decode('UTF-8') - - return self.find_element(by=AppiumBy.IMAGE, value=b64_data) - - def find_elements_by_image(self, img_path: str) -> List['WebElement']: - """Finds a portion of a screenshot by an image. - - Uses driver.find_image_occurrence under the hood. Note that this will - only ever return at most one element - - Args: - img_path: a string corresponding to the path of a image - - Return: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - """ - with open(img_path, 'rb') as i_file: - b64_data = base64.b64encode(i_file.read()).decode('UTF-8') - - return self.find_elements(by=AppiumBy.IMAGE, value=b64_data) diff --git a/appium/webdriver/extensions/search_context/windows.py b/appium/webdriver/extensions/search_context/windows.py deleted file mode 100644 index 016f28c29..000000000 --- a/appium/webdriver/extensions/search_context/windows.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/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 typing import TYPE_CHECKING, List - -from appium.common.logger import logger -from appium.protocols.webdriver.can_find_elements import CanFindElements -from appium.webdriver.common.appiumby import AppiumBy - -if TYPE_CHECKING: - from appium.webdriver.webelement import WebElement - - -class WindowsSearchContext(CanFindElements): - """Define search context for Windows""" - - def find_element_by_windows_uiautomation(self, win_uiautomation: str) -> 'WebElement': - """[Deprecated] Finds an element by windows uiautomation - - Args: - win_uiautomation: The element name in the windows UIAutomation selector - - Usage: - driver.find_element_by_windows_uiautomation() - - Returns: - `appium.webdriver.webelement.WebElement`: The found element - - """ - logger.warning( - "[Deprecated] '-windows uiautomation' selector is deprecated. Please use other locators like id." - ) - return self.find_element(by=AppiumBy.WINDOWS_UI_AUTOMATION, value=win_uiautomation) - - def find_elements_by_windows_uiautomation(self, win_uiautomation: str) -> List['WebElement']: - """[Deprecated] Finds elements by windows uiautomation - - Args: - win_uiautomation: The element name in the windows UIAutomation selector - - Usage: - driver.find_elements_by_windows_uiautomation() - - Returns: - :obj:`list` of :obj:`appium.webdriver.webelement.WebElement`: The found elements - """ - logger.warning( - "[Deprecated] '-windows uiautomation' selector is deprecated. Please use other locators like id." - ) - return self.find_elements(by=AppiumBy.WINDOWS_UI_AUTOMATION, value=win_uiautomation) diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index e26d00770..5815069bd 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -52,7 +52,6 @@ from .extensions.log_event import LogEvent from .extensions.remote_fs import RemoteFS from .extensions.screen_record import ScreenRecord -from .extensions.search_context import AppiumSearchContext from .extensions.session import Session from .extensions.settings import Settings from .mobilecommand import MobileCommand as Command @@ -172,7 +171,6 @@ def add_command(self) -> Tuple[str, str]: class WebDriver( webdriver.Remote, - AppiumSearchContext, ActionHelpers, Activities, Applications, diff --git a/test/functional/android/search_context/find_by_image_tests.py b/test/functional/android/search_context/find_by_image_tests.py index ab12e8969..2ac4354ab 100644 --- a/test/functional/android/search_context/find_by_image_tests.py +++ b/test/functional/android/search_context/find_by_image_tests.py @@ -73,6 +73,3 @@ def test_find_throws_no_such_element(self) -> None: with pytest.raises(TimeoutException): wait_for_element(self.driver, AppiumBy.IMAGE, b64_data, timeout_sec=3) - - with pytest.raises(NoSuchElementException): - self.driver.find_element_by_image(image_path) diff --git a/test/unit/webdriver/search_context/android_test.py b/test/unit/webdriver/search_context/android_test.py index 9932945ba..c40735fc0 100644 --- a/test/unit/webdriver/search_context/android_test.py +++ b/test/unit/webdriver/search_context/android_test.py @@ -49,7 +49,8 @@ def test_find_elements_by_android_data_matcher(self): httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/elements'), - body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "element-id1"}, {"element-6066-11e4-a52e-4f735466cecf": "element-id2"}]}', + body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "element-id1"}, ' + '{"element-6066-11e4-a52e-4f735466cecf": "element-id2"}]}', ) els = driver.find_elements( by=AppiumBy.ANDROID_DATA_MATCHER, value=json.dumps({'name': 'title', 'args': ['title', 'Animation']}) @@ -103,7 +104,8 @@ def test_find_elements_by_android_data_matcher(self): httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/element/element_id/elements'), - body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "child-element-id1"}, {"element-6066-11e4-a52e-4f735466cecf": "child-element-id2"}]}', + body='{"value": [{"element-6066-11e4-a52e-4f735466cecf": "child-element-id1"}, ' + '{"element-6066-11e4-a52e-4f735466cecf": "child-element-id2"}]}', ) els = element.find_elements( by=AppiumBy.ANDROID_DATA_MATCHER, value=json.dumps({'name': 'title', 'args': ['title', 'Animation']}) From 37bcda583d40ab4f1da78724e04139919974472a Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sat, 25 Jun 2022 08:56:37 +0200 Subject: [PATCH 2/2] fix import --- appium/webdriver/webelement.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/appium/webdriver/webelement.py b/appium/webdriver/webelement.py index 2e4fca90c..67f9a27c1 100644 --- a/appium/webdriver/webelement.py +++ b/appium/webdriver/webelement.py @@ -20,11 +20,10 @@ from appium.webdriver.common.appiumby import AppiumBy -from .extensions.search_context import AppiumWebElementSearchContext from .mobilecommand import MobileCommand as Command -class WebElement(SeleniumWebElement, AppiumWebElementSearchContext): +class WebElement(SeleniumWebElement): _execute: Callable _id: str