From 83f559f1c373281757ab2f07041ba9d69a7d9d31 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Fri, 1 Sep 2023 19:20:15 +0200 Subject: [PATCH] refactor!: remove several previously deprecated APIs --- appium/webdriver/common/mobileby.py | 22 --- .../extensions/android/activities.py | 51 ------- appium/webdriver/extensions/android/common.py | 30 ---- appium/webdriver/extensions/applications.py | 53 ------- appium/webdriver/extensions/ime.py | 141 ------------------ appium/webdriver/extensions/session.py | 43 +----- appium/webdriver/mobilecommand.py | 16 -- appium/webdriver/webdriver.py | 60 +------- appium/webdriver/webelement.py | 49 ------ test/functional/android/activities_tests.py | 28 +++- test/functional/android/applications_tests.py | 13 -- test/functional/android/webelement_tests.py | 3 +- test/functional/ios/keyboard_tests.py | 8 +- test/functional/ios/webdriver_tests.py | 37 +---- test/unit/webdriver/app_test.py | 27 ---- test/unit/webdriver/webdriver_test.py | 29 +--- test/unit/webdriver/webelement_test.py | 13 -- 17 files changed, 36 insertions(+), 587 deletions(-) delete mode 100644 appium/webdriver/common/mobileby.py delete mode 100644 appium/webdriver/extensions/ime.py diff --git a/appium/webdriver/common/mobileby.py b/appium/webdriver/common/mobileby.py deleted file mode 100644 index 986ad736..00000000 --- a/appium/webdriver/common/mobileby.py +++ /dev/null @@ -1,22 +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 appium.webdriver.common.appiumby import AppiumBy - - -class MobileBy(AppiumBy): - """ - deprecated:: 2.1.0 - Please use 'from appium.webdriver.common.appiumby import AppiumBy' instead of 'MobileBy'. - """ diff --git a/appium/webdriver/extensions/android/activities.py b/appium/webdriver/extensions/android/activities.py index e0cb84d5..2e9ed68d 100644 --- a/appium/webdriver/extensions/android/activities.py +++ b/appium/webdriver/extensions/android/activities.py @@ -12,9 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import warnings -from typing import TYPE_CHECKING, cast - from selenium.common.exceptions import TimeoutException, UnknownMethodException from selenium.webdriver.support.ui import WebDriverWait @@ -23,52 +20,8 @@ from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence from appium.webdriver.mobilecommand import MobileCommand as Command -if TYPE_CHECKING: - from appium.webdriver.webdriver import WebDriver - class Activities(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): - def start_activity(self, app_package: str, app_activity: str, **opts: str) -> 'WebDriver': - """Opens an arbitrary activity during a test. If the activity belongs to - another application, that application is started and the activity is opened. - deprecated:: 2.9.0 - - This is an Android-only method. - - Args: - app_package: The package containing the activity to start. - app_activity: The activity to start. - - Keyword Args: - app_wait_package (str): Begin automation after this package starts. - app_wait_activity (str): Begin automation after this activity starts. - intent_action (str): Intent to start. - intent_category (str): Intent category to start. - intent_flags (str): Flags to send to the intent. - optional_intent_arguments (str): Optional arguments to the intent. - dont_stop_app_on_reset (str): Should the app be stopped on reset? - """ - warnings.warn( - 'The "session" API is deprecated. Use "mobile: startActivity" extension instead.', - DeprecationWarning, - ) - - data = {'appPackage': app_package, 'appActivity': app_activity} - arguments = { - 'app_wait_package': 'appWaitPackage', - 'app_wait_activity': 'appWaitActivity', - 'intent_action': 'intentAction', - 'intent_category': 'intentCategory', - 'intent_flags': 'intentFlags', - 'optional_intent_arguments': 'optionalIntentArguments', - 'dont_stop_app_on_reset': 'dontStopAppOnReset', - } - for key, value in arguments.items(): - if key in opts: - data[value] = opts[key] - self.execute(Command.START_ACTIVITY, data) - return cast('WebDriver', self) - @property def current_activity(self) -> str: """Retrieves the current activity running on the device. @@ -109,7 +62,3 @@ def _add_commands(self) -> None: 'GET', '/session/$sessionId/appium/device/current_activity', ) - commands[Command.START_ACTIVITY] = ( - 'POST', - '/session/$sessionId/appium/device/start_activity', - ) diff --git a/appium/webdriver/extensions/android/common.py b/appium/webdriver/extensions/android/common.py index f6aa9270..d680220f 100644 --- a/appium/webdriver/extensions/android/common.py +++ b/appium/webdriver/extensions/android/common.py @@ -26,32 +26,6 @@ class Common(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): - def end_test_coverage(self, intent: str, path: str) -> Any: - """Ends the coverage collection and pull the coverage.ec file from the device. - deprecated:: 2.9.0 - - Android only. - See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/android-coverage.md - - Args: - intent: description of operation to be performed - path: path to coverage.ec file to be pulled from the device - - Returns: - TODO - """ - warnings.warn( - 'This API is deprecated and will be removed in future versions', - DeprecationWarning, - ) - return self.execute( - Command.END_TEST_COVERAGE, - { - 'intent': intent, - 'path': path, - }, - )['value'] - def open_notifications(self) -> 'WebDriver': """Open notification shade in Android (API Level 18 and above) @@ -83,10 +57,6 @@ def _add_commands(self) -> None: 'GET', '/session/$sessionId/appium/device/current_package', ) - commands[Command.END_TEST_COVERAGE] = ( - 'POST', - '/session/$sessionId/appium/app/end_test_coverage', - ) commands[Command.OPEN_NOTIFICATIONS] = ( 'POST', '/session/$sessionId/appium/device/open_notifications', diff --git a/appium/webdriver/extensions/applications.py b/appium/webdriver/extensions/applications.py index d4951b9d..673c6fca 100644 --- a/appium/webdriver/extensions/applications.py +++ b/appium/webdriver/extensions/applications.py @@ -11,7 +11,6 @@ # 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, Union, cast from selenium.common.exceptions import InvalidArgumentException, UnknownMethodException @@ -145,39 +144,6 @@ def remove_app(self, app_id: str, **options: Any) -> 'WebDriver': self.mark_extension_absence(ext_name).execute(Command.REMOVE_APP, data) return cast('WebDriver', self) - 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 cast('WebDriver', self) - - 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 cast('WebDriver', self) - def terminate_app(self, app_id: str, **options: Any) -> bool: """Terminates the application if it is running. @@ -283,22 +249,6 @@ def app_strings(self, language: Union[str, None] = None, string_file: Union[str, # TODO: Remove the fallback return self.mark_extension_absence(ext_name).execute(Command.GET_APP_STRINGS, data)['value'] - 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 cast('WebDriver', self) - def _add_commands(self) -> None: # noinspection PyProtectedMember,PyUnresolvedReferences commands = self.command_executor._commands @@ -322,6 +272,3 @@ def _add_commands(self) -> None: '/session/$sessionId/appium/device/app_state', ) commands[Command.GET_APP_STRINGS] = ('POST', '/session/$sessionId/appium/app/strings') - commands[Command.RESET] = ('POST', '/session/$sessionId/appium/app/reset') - commands[Command.LAUNCH_APP] = ('POST', '/session/$sessionId/appium/app/launch') - commands[Command.CLOSE_APP] = ('POST', '/session/$sessionId/appium/app/close') diff --git a/appium/webdriver/extensions/ime.py b/appium/webdriver/extensions/ime.py deleted file mode 100644 index 2a5f188c..00000000 --- a/appium/webdriver/extensions/ime.py +++ /dev/null @@ -1,141 +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 warnings -from typing import TYPE_CHECKING, List, cast - -from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands - -from ..mobilecommand import MobileCommand as Command - -if TYPE_CHECKING: - from appium.webdriver.webdriver import WebDriver - - -class IME(CanExecuteCommands): - @property - def available_ime_engines(self) -> List[str]: - """Get the available input methods for an Android device. - - Package and activity are returned (e.g., ['com.android.inputmethod.latin/.LatinIME']) - Android only. - - deprecated:: 2.0.0 - - Returns: - :obj:`list` of :obj:`str`: The available input methods for an Android device - """ - warnings.warn( - 'The "available_ime_engines" API is deprecated and will be removed in future versions. ' - 'Use "mobile: shell" extension instead', - DeprecationWarning, - ) - - return self.execute(Command.GET_AVAILABLE_IME_ENGINES, {})['value'] # pylint: disable=unsubscriptable-object - - def is_ime_active(self) -> bool: - """Checks whether the device has IME service active. - Android only. - - deprecated:: 2.0.0 - - Returns: - `True` if IME service is active - """ - warnings.warn( - 'The "is_ime_active" API is deprecated and will be removed in future versions. ' - 'Use "mobile: shell" extension instead', - DeprecationWarning, - ) - - return self.execute(Command.IS_IME_ACTIVE, {})['value'] # pylint: disable=unsubscriptable-object - - def activate_ime_engine(self, engine: str) -> 'WebDriver': - """Activates the given IME engine on the device. - - Android only. - - deprecated:: 2.0.0 - - Args: - engine: the package and activity of the IME engine to activate - (e.g., 'com.android.inputmethod.latin/.LatinIME') - - Returns: - Union['WebDriver', 'IME']: Self instance - """ - warnings.warn( - 'The "activate_ime_engine" API is deprecated and will be removed in future versions. ' - 'Use "mobile: shell" extension instead', - DeprecationWarning, - ) - - data = {'engine': engine} - self.execute(Command.ACTIVATE_IME_ENGINE, data) - return cast('WebDriver', self) - - def deactivate_ime_engine(self) -> 'WebDriver': - """Deactivates the currently active IME engine on the device. - - Android only. - - deprecated:: 2.0.0 - - Returns: - Union['WebDriver', 'IME']: Self instance - """ - warnings.warn( - 'The "deactivate_ime_engine" API is deprecated and will be removed in future versions. ' - 'Use "mobile: shell" extension instead', - DeprecationWarning, - ) - - self.execute(Command.DEACTIVATE_IME_ENGINE, {}) - return cast('WebDriver', self) - - @property - def active_ime_engine(self) -> str: - """Returns the activity and package of the currently active IME engine - (e.g., 'com.android.inputmethod.latin/.LatinIME'). - - Android only. - - deprecated:: 2.0.0 - - Returns: - str: The activity and package of the currently active IME engine - """ - warnings.warn( - 'The "active_ime_engine" API is deprecated and will be removed in future versions. ' - 'Use "mobile: shell" extension instead', - DeprecationWarning, - ) - - return self.execute(Command.GET_ACTIVE_IME_ENGINE, {})['value'] # pylint: disable=unsubscriptable-object - - def _add_commands(self) -> None: - """Add IME commands. They are not in W3C spec.""" - # noinspection PyProtectedMember,PyUnresolvedReferences - commands = self.command_executor._commands - commands[Command.GET_AVAILABLE_IME_ENGINES] = ( - 'GET', - '/session/$sessionId/ime/available_engines', - ) - commands[Command.IS_IME_ACTIVE] = ('GET', '/session/$sessionId/ime/activated') - commands[Command.ACTIVATE_IME_ENGINE] = ('POST', '/session/$sessionId/ime/activate') - commands[Command.DEACTIVATE_IME_ENGINE] = ('POST', '/session/$sessionId/ime/deactivate') - commands[Command.GET_ACTIVE_IME_ENGINE] = ( - 'GET', - '/session/$sessionId/ime/active_engine', - ) diff --git a/appium/webdriver/extensions/session.py b/appium/webdriver/extensions/session.py index dfd387ca..8960066d 100644 --- a/appium/webdriver/extensions/session.py +++ b/appium/webdriver/extensions/session.py @@ -12,8 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -import warnings -from typing import Any, Dict, List +from typing import Dict from appium.common.logger import logger from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands @@ -22,42 +21,6 @@ class Session(CanExecuteCommands): - @property - def session(self) -> Dict[str, Any]: - """Retrieves session information from the current session - deprecated:: 2.0.0 - - Usage: - session = driver.session - - Returns: - `dict`: containing information from the current session - """ - warnings.warn( - 'The "session" API is deprecated and will be removed in future versions', - DeprecationWarning, - ) - - return self.execute(Command.GET_SESSION)['value'] - - @property - def all_sessions(self) -> List[Dict[str, Any]]: - """Retrieves all sessions that are open - deprecated:: 2.0.0 - - Usage: - sessions = driver.all_sessions - - Returns: - :obj:`list` of :obj:`dict`: containing all open sessions - """ - warnings.warn( - 'The "all_sessions" API is deprecated and will be removed in future versions', - DeprecationWarning, - ) - - return self.execute(Command.GET_ALL_SESSIONS)['value'] - @property def events(self) -> Dict: """Retrieves events information from the current session @@ -69,8 +32,7 @@ def events(self) -> Dict: `dict`: containing events timing information from the current session """ try: - session = self.session - return session['events'] + return self.execute(Command.GET_SESSION)['value']['events'] except Exception as e: logger.warning('Could not find events information in the session. Error: %s', e) return {} @@ -79,4 +41,3 @@ def _add_commands(self) -> None: # noinspection PyProtectedMember,PyUnresolvedReferences commands = self.command_executor._commands commands[Command.GET_SESSION] = ('GET', '/session/$sessionId') - commands[Command.GET_ALL_SESSIONS] = ('GET', '/sessions') diff --git a/appium/webdriver/mobilecommand.py b/appium/webdriver/mobilecommand.py index 2a83f1a4..e1648242 100644 --- a/appium/webdriver/mobilecommand.py +++ b/appium/webdriver/mobilecommand.py @@ -16,7 +16,6 @@ class MobileCommand: # Common GET_SESSION = 'getSession' - GET_ALL_SESSIONS = 'getAllSessions' GET_STATUS = 'getStatus' @@ -24,13 +23,6 @@ class MobileCommand: GET_LOCATION = 'getLocation' SET_LOCATION = 'setLocation' - ## MJSONWP for Selenium v4 - GET_AVAILABLE_IME_ENGINES = 'getAvailableIMEEngines' - IS_IME_ACTIVE = 'isIMEActive' - ACTIVATE_IME_ENGINE = 'activateIMEEngine' - DEACTIVATE_IME_ENGINE = 'deactivateIMEEngine' - GET_ACTIVE_IME_ENGINE = 'getActiveEngine' - CLEAR = 'clear' LOCATION_IN_VIEW = 'locationInView' @@ -41,12 +33,6 @@ class MobileCommand: TOUCH_ACTION = 'touchAction' MULTI_ACTION = 'multiAction' - SET_IMMEDIATE_VALUE = 'setImmediateValue' - REPLACE_KEYS = 'replaceKeys' - - LAUNCH_APP = 'launchApp' - CLOSE_APP = 'closeApp' - RESET = 'reset' BACKGROUND = 'background' GET_APP_STRINGS = 'getAppStrings' @@ -96,14 +82,12 @@ class MobileCommand: # Android OPEN_NOTIFICATIONS = 'openNotifications' - START_ACTIVITY = 'startActivity' GET_CURRENT_ACTIVITY = 'getCurrentActivity' GET_CURRENT_PACKAGE = 'getCurrentPackage' GET_SYSTEM_BARS = 'getSystemBars' GET_DISPLAY_DENSITY = 'getDisplayDensity' TOGGLE_WIFI = 'toggleWiFi' TOGGLE_LOCATION_SERVICES = 'toggleLocationServices' - END_TEST_COVERAGE = 'endTestCoverage' GET_PERFORMANCE_DATA_TYPES = 'getPerformanceDataTypes' GET_PERFORMANCE_DATA = 'getPerformanceData' GET_NETWORK_CONNECTION = 'getNetworkConnection' diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 48b7993f..86ca1d1a 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -14,7 +14,6 @@ # pylint: disable=too-many-lines,too-many-public-methods,too-many-statements,no-self-use -import warnings from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union from selenium import webdriver @@ -52,7 +51,6 @@ from .extensions.execute_mobile_command import ExecuteMobileCommand from .extensions.hw_actions import HardwareActions from .extensions.images_comparison import ImagesComparison -from .extensions.ime import IME from .extensions.keyboard import Keyboard from .extensions.location import Location from .extensions.log_event import LogEvent @@ -190,7 +188,6 @@ class WebDriver( Gsm, HardwareActions, ImagesComparison, - IME, Keyboard, Location, LogEvent, @@ -207,12 +204,6 @@ class WebDriver( def __init__( self, command_executor: Union[str, AppiumConnection] = 'http://127.0.0.1:4444/wd/hub', - # TODO: Remove the deprecated arg - desired_capabilities: Optional[Dict] = None, - # TODO: Remove the deprecated arg - browser_profile: Union[str, None] = None, - # TODO: Remove the deprecated arg - proxy: Union[str, None] = None, keep_alive: bool = True, direct_connection: bool = True, extensions: Optional[List['WebDriver']] = None, @@ -235,28 +226,9 @@ def __init__( if isinstance(command_executor, str): command_executor = AppiumConnection(command_executor, keep_alive=keep_alive) - if browser_profile is not None: - warnings.warn('browser_profile argument is deprecated and has no effect', DeprecationWarning) - - if proxy is not None: - warnings.warn('proxy argument is deprecated and has no effect', DeprecationWarning) - - if desired_capabilities is not None: - warnings.warn( - 'desired_capabilities argument is deprecated and will be removed in future versions. ' - 'Use options instead.', - DeprecationWarning, - ) - # TODO: Remove the fallback after desired_capabilities removal - dst_options = ( - AppiumOptions().load_capabilities(desired_capabilities) - if desired_capabilities is not None and options is None - else options - ) - super().__init__( command_executor=command_executor, - options=dst_options, + options=options, ) if hasattr(self, 'command_executor'): @@ -458,28 +430,6 @@ def create_web_element(self, element_id: Union[int, str]) -> MobileWebElement: """ return MobileWebElement(self, element_id) - def set_value(self, element: MobileWebElement, value: str) -> 'WebDriver': - """Set the value on an element in the application. - deprecated:: 2.8.1 - - Args: - element: the element whose value will be set - value: the value to set on the element - - Returns: - `appium.webdriver.webdriver.WebDriver`: Self instance - """ - warnings.warn( - 'The "setValue" API is deprecated and will be removed in future versions. ' - 'Instead the "send_keys" API or W3C Actions can be used. ' - 'See https://github.com/appium/python-client/pull/831', - DeprecationWarning, - ) - - data = {'text': value} - self.execute(Command.SET_IMMEDIATE_VALUE, data) - return self - @property def switch_to(self) -> MobileSwitchTo: """Returns an object containing all options to switch focus into @@ -565,16 +515,8 @@ def _add_commands(self) -> None: # FIXME: remove after a while as MJSONWP commands[Command.TOUCH_ACTION] = ('POST', '/session/$sessionId/touch/perform') commands[Command.MULTI_ACTION] = ('POST', '/session/$sessionId/touch/multi/perform') - commands[Command.SET_IMMEDIATE_VALUE] = ( - 'POST', - '/session/$sessionId/appium/element/$id/value', - ) # TODO Move commands for element to webelement - commands[Command.REPLACE_KEYS] = ( - 'POST', - '/session/$sessionId/appium/element/$id/replace_value', - ) commands[Command.CLEAR] = ('POST', '/session/$sessionId/element/$id/clear') commands[Command.LOCATION_IN_VIEW] = ( 'GET', diff --git a/appium/webdriver/webelement.py b/appium/webdriver/webelement.py index 87b2dc9a..b49258d2 100644 --- a/appium/webdriver/webelement.py +++ b/appium/webdriver/webelement.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import warnings from typing import Callable, Dict, List, Optional, Union from selenium.webdriver.common.utils import keys_to_typing @@ -159,33 +158,6 @@ def clear(self) -> 'WebElement': self._execute(Command.CLEAR, data) return self - def set_text(self, keys: str = '') -> 'WebElement': - """Sends text to the element. - deprecated:: 2.8.1 - - Previous text is removed. - Android only. - - Args: - keys: the text to be sent to the element. - - Usage: - element.set_text('some text') - - Returns: - `appium.webdriver.webelement.WebElement` - """ - warnings.warn( - 'The "setText" API is deprecated and will be removed in future versions. ' - 'Instead the "send_keys" API or W3C Actions can be used. ' - 'See https://github.com/appium/python-client/pull/831', - DeprecationWarning, - ) - - data = {'text': keys} - self._execute(Command.REPLACE_KEYS, data) - return self - @property def location_in_view(self) -> Dict[str, int]: """Gets the location of an element relative to the view. @@ -200,27 +172,6 @@ def location_in_view(self) -> Dict[str, int]: """ return self._execute(Command.LOCATION_IN_VIEW)['value'] - def set_value(self, value: str) -> 'WebElement': - """Set the value on this element in the application - deprecated:: 2.8.1 - - Args: - value: The value to be set - - Returns: - `appium.webdriver.webelement.WebElement` - """ - warnings.warn( - 'The "setValue" API is deprecated and will be removed in future versions. ' - 'Instead the "send_keys" API or W3C Actions can be used. ' - 'See https://github.com/appium/python-client/pull/831', - DeprecationWarning, - ) - - data = {'text': value} - self._execute(Command.SET_IMMEDIATE_VALUE, data) - return self - # Override def send_keys(self, *value: str) -> 'WebElement': """Simulates typing into the element. diff --git a/test/functional/android/activities_tests.py b/test/functional/android/activities_tests.py index 948248e6..4f60c5b7 100644 --- a/test/functional/android/activities_tests.py +++ b/test/functional/android/activities_tests.py @@ -22,17 +22,37 @@ def test_current_activity(self) -> None: assert '.ApiDemos' == activity def test_start_activity_this_app(self) -> None: - self.driver.start_activity(APIDEMO_PKG_NAME, '.ApiDemos') + self.driver.execute_script( + 'mobile: startActivity', + { + 'component': f'{APIDEMO_PKG_NAME}/.ApiDemos', + }, + ) self._assert_activity_contains('Demos') - self.driver.start_activity(APIDEMO_PKG_NAME, '.accessibility.AccessibilityNodeProviderActivity') + self.driver.execute_script( + 'mobile: startActivity', + { + 'component': f'{APIDEMO_PKG_NAME}/.accessibility.AccessibilityNodeProviderActivity', + }, + ) self._assert_activity_contains('Node') def test_start_activity_other_app(self) -> None: - self.driver.start_activity(APIDEMO_PKG_NAME, '.ApiDemos') + self.driver.execute_script( + 'mobile: startActivity', + { + 'component': f'{APIDEMO_PKG_NAME}/.ApiDemos', + }, + ) self._assert_activity_contains('Demos') - self.driver.start_activity('com.google.android.deskclock', 'com.android.deskclock.DeskClock') + self.driver.execute_script( + 'mobile: startActivity', + { + 'component': f'{APIDEMO_PKG_NAME}/com.android.deskclock.DeskClock', + }, + ) self._assert_activity_contains('Clock') def _assert_activity_contains(self, activity: str) -> None: diff --git a/test/functional/android/applications_tests.py b/test/functional/android/applications_tests.py index c15a49f3..9035c04e 100644 --- a/test/functional/android/applications_tests.py +++ b/test/functional/android/applications_tests.py @@ -14,7 +14,6 @@ # limitations under the License. import os -from time import sleep from appium.webdriver.applicationstate import ApplicationState @@ -25,8 +24,6 @@ class TestApplications(BaseTestCase): def test_background_app(self) -> None: self.driver.background_app(1) - sleep(3) - self.driver.launch_app() def test_is_app_installed(self) -> None: assert not self.driver.is_app_installed('sdfsdf') @@ -43,12 +40,6 @@ def test_remove_app(self) -> None: self.driver.remove_app(APIDEMO_PKG_NAME) assert not self.driver.is_app_installed(APIDEMO_PKG_NAME) - def test_close_and_launch_app(self) -> None: - self.driver.close_app() - self.driver.launch_app() - activity = self.driver.current_activity - assert '.ApiDemos' == activity - def test_app_management(self) -> None: app_id = self.driver.current_package assert self.driver.query_app_state(app_id) == ApplicationState.RUNNING_IN_FOREGROUND @@ -68,7 +59,3 @@ def test_app_strings_with_language(self) -> None: def test_app_strings_with_language_and_file(self) -> None: strings = self.driver.app_strings('en', 'some_file') assert u'You can\'t wipe my data, you are a monkey!' == strings[u'monkey_wipe_data'] - - def test_reset(self) -> None: - self.driver.reset() - assert self.driver.is_app_installed(APIDEMO_PKG_NAME) diff --git a/test/functional/android/webelement_tests.py b/test/functional/android/webelement_tests.py index d631c396..9a8ba1fd 100644 --- a/test/functional/android/webelement_tests.py +++ b/test/functional/android/webelement_tests.py @@ -37,7 +37,8 @@ def test_set_text(self) -> None: el = wait_for_element(self.driver, AppiumBy.CLASS_NAME, 'android.widget.EditText') el.send_keys('original text') - el.set_text('new text') + el.clear() + el.send_keys('new text') assert 'new text' == el.text diff --git a/test/functional/ios/keyboard_tests.py b/test/functional/ios/keyboard_tests.py index 5397e2ce..d07e5e70 100644 --- a/test/functional/ios/keyboard_tests.py +++ b/test/functional/ios/keyboard_tests.py @@ -30,7 +30,7 @@ def test_hide_keyboard(self) -> None: el = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeTextField')[0] el.click() - el.set_value('Testing') + el.send_keys('Testing') assert self._get_keyboard_el().is_displayed() @@ -44,7 +44,7 @@ def test_hide_keyboard_presskey_strategy(self) -> None: el = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeTextField')[0] el.click() - el.set_value('Testing') + el.send_keys('Testing') assert self._get_keyboard_el().is_displayed() @@ -58,7 +58,7 @@ def test_hide_keyboard_no_key_name(self) -> None: el = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeTextField')[0] el.click() - el.set_value('Testing') + el.send_keys('Testing') assert self._get_keyboard_el().is_displayed() @@ -72,7 +72,7 @@ def test_is_keyboard_shown(self) -> None: el = self.driver.find_elements(by=AppiumBy.CLASS_NAME, value='XCUIElementTypeTextField')[0] el.click() - el.set_value('Testing') + el.send_keys('Testing') assert self.driver.is_keyboard_shown() def _get_keyboard_el(self) -> 'WebElement': diff --git a/test/functional/ios/webdriver_tests.py b/test/functional/ios/webdriver_tests.py index 8e26fc91..9cb8c62d 100644 --- a/test/functional/ios/webdriver_tests.py +++ b/test/functional/ios/webdriver_tests.py @@ -12,50 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import TYPE_CHECKING - -import pytest -from selenium.webdriver.support.ui import WebDriverWait - -from appium import webdriver -from appium.options.common import AppiumOptions from appium.webdriver.applicationstate import ApplicationState from appium.webdriver.common.appiumby import AppiumBy from test.functional.ios.helper.test_helper import BaseTestCase -from test.functional.test_helper import get_available_from_port_range, wait_for_condition -from test.helpers.constants import SERVER_URL_BASE +from test.functional.test_helper import wait_for_condition -from ..test_helper import is_ci from .helper import desired_capabilities -if TYPE_CHECKING: - from appium.webdriver.webdriver import WebDriver - class TestWebDriver(BaseTestCase): - # TODO Due to not created 2nd session somehow - @pytest.mark.skipif(condition=is_ci(), reason='Need to fix flaky test during running on CI.') - def test_all_sessions(self) -> None: - port = get_available_from_port_range(8200, 8300) - caps = desired_capabilities.get_desired_capabilities('UICatalog.app.zip') - caps['deviceName'] = 'iPhone Xs Max' - caps['wdaLocalPort'] = port - - class session_counts_is_two: - TIMEOUT = 10 - - def __call__(self, driver: 'WebDriver') -> bool: - return len(driver.all_sessions) == 2 - - driver2 = None - try: - driver2 = webdriver.Remote(SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps)) - WebDriverWait(driver2, session_counts_is_two.TIMEOUT).until(session_counts_is_two()) - assert len(self.driver.all_sessions) == 2 - finally: - if driver2 is not None: - driver2.quit() - def test_app_management(self) -> None: # this only works in Xcode9+ if float(desired_capabilities.get_desired_capabilities(desired_capabilities.BUNDLE_ID)['platformVersion']) < 11: diff --git a/test/unit/webdriver/app_test.py b/test/unit/webdriver/app_test.py index 1a8b0247..7cb7b6b3 100644 --- a/test/unit/webdriver/app_test.py +++ b/test/unit/webdriver/app_test.py @@ -20,17 +20,6 @@ class TestWebDriverApp(object): - @httpretty.activate - def test_reset(self): - driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/app/reset'), body='{"value": ""}' - ) - result = driver.reset() - - assert {'sessionId': '1234567890'}, get_httpretty_request_body(httpretty.last_request()) - assert isinstance(result, WebDriver) - @httpretty.activate def test_install_app(self): driver = android_w3c_driver() @@ -104,22 +93,6 @@ def test_background_app(self): assert {'app': 0}, get_httpretty_request_body(httpretty.last_request()) assert isinstance(result, WebDriver) - @httpretty.activate - def test_launch_app(self): - driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/app/launch'), body='{"value": }' - ) - assert isinstance(driver.launch_app(), WebDriver) - - @httpretty.activate - def test_close_app(self): - driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/app/close'), body='{"value": }' - ) - assert isinstance(driver.close_app(), WebDriver) - @httpretty.activate def test_query_app_state(self): driver = android_w3c_driver() diff --git a/test/unit/webdriver/webdriver_test.py b/test/unit/webdriver/webdriver_test.py index 70b09600..8872a46c 100644 --- a/test/unit/webdriver/webdriver_test.py +++ b/test/unit/webdriver/webdriver_test.py @@ -174,29 +174,6 @@ def test_create_session_register_uridirect_no_direct_connect_path(self): assert SERVER_URL_BASE == driver.command_executor._url assert ['NATIVE_APP', 'CHROMIUM'] == driver.contexts - @httpretty.activate - def test_get_all_sessions(self): - driver = ios_w3c_driver() - httpretty.register_uri( - httpretty.GET, - appium_command('/sessions'), - body=json.dumps({'value': {'deviceName': 'iPhone Simulator', 'events': {'simStarted': [1234567891]}}}), - ) - session = driver.all_sessions - assert len(session) != 1 - - @httpretty.activate - def test_get_session(self): - driver = ios_w3c_driver() - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890'), - body=json.dumps({'value': {'deviceName': 'iPhone Simulator', 'events': {'simStarted': [1234567890]}}}), - ) - session = driver.session - assert session['deviceName'] == 'iPhone Simulator' - assert session['events']['simStarted'] == [1234567890] - @httpretty.activate def test_get_events(self): driver = ios_w3c_driver() @@ -391,20 +368,18 @@ class CustomAppiumConnection(AppiumConnection): class SubWebDriver(WebDriver): - def __init__(self, command_executor, desired_capabilities=None, direct_connection=False, options=None): + def __init__(self, command_executor, direct_connection=False, options=None): super().__init__( command_executor=command_executor, - desired_capabilities=desired_capabilities, direct_connection=direct_connection, options=options, ) class SubSubWebDriver(SubWebDriver): - def __init__(self, command_executor, desired_capabilities=None, direct_connection=False, options=None): + def __init__(self, command_executor, direct_connection=False, options=None): super().__init__( command_executor=command_executor, - desired_capabilities=desired_capabilities, direct_connection=direct_connection, options=options, ) diff --git a/test/unit/webdriver/webelement_test.py b/test/unit/webdriver/webelement_test.py index aa6168f6..3bcb1192 100644 --- a/test/unit/webdriver/webelement_test.py +++ b/test/unit/webdriver/webelement_test.py @@ -13,7 +13,6 @@ # limitations under the License. import json -import os import tempfile import httpretty @@ -36,18 +35,6 @@ def test_status(self): assert s == response - @httpretty.activate - def test_set_value(self): - driver = android_w3c_driver() - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/element/element_id/value')) - - element = MobileWebElement(driver, 'element_id') - value = 'happy testing' - element.set_value(value) - - d = get_httpretty_request_body(httpretty.last_request()) - assert d['text'] == value - @httpretty.activate def test_send_key(self): driver = android_w3c_driver()