diff --git a/appium/webdriver/extensions/android/activities.py b/appium/webdriver/extensions/android/activities.py index 76da521b..cdcfdc25 100644 --- a/appium/webdriver/extensions/android/activities.py +++ b/appium/webdriver/extensions/android/activities.py @@ -12,35 +12,33 @@ # See the License for the specific language governing permissions and # limitations under the License. -from selenium.common.exceptions import TimeoutException, UnknownMethodException +from selenium.common.exceptions import TimeoutException from selenium.webdriver.support.ui import WebDriverWait from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from appium.webdriver.mobilecommand import MobileCommand as Command -class Activities(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class Activities(CanExecuteCommands, CanExecuteScripts): @property def current_activity(self) -> str: """Retrieves the current activity running on the device. + Requires the Appium driver to support the `mobile: getCurrentActivity` execute method. + Returns: str: The current activity name running on the device """ ext_name = 'mobile: getCurrentActivity' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name) - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.GET_CURRENT_ACTIVITY)['value'] + return self.execute_script(ext_name) def wait_activity(self, activity: str, timeout: int, interval: int = 1) -> bool: """Wait for an activity: block until target activity presents or time out. This is an Android-only method. + Requires the Appium driver to support the `mobile: getCurrentActivity` execute method. + Args: activity: target activity timeout: max wait time, in seconds @@ -56,10 +54,3 @@ def wait_activity(self, activity: str, timeout: int, interval: int = 1) -> bool: return True except TimeoutException: return False - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.GET_CURRENT_ACTIVITY, - 'GET', - '/session/$sessionId/appium/device/current_activity', - ) diff --git a/appium/webdriver/extensions/android/common.py b/appium/webdriver/extensions/android/common.py index f8ad2c72..a1036c82 100644 --- a/appium/webdriver/extensions/android/common.py +++ b/appium/webdriver/extensions/android/common.py @@ -33,6 +33,3 @@ def open_notifications(self) -> Self: def current_package(self) -> str: """Retrieves the current package running on the device.""" return self.execute_script('mobile: getCurrentPackage') - - def _add_commands(self) -> None: - pass diff --git a/appium/webdriver/extensions/android/display.py b/appium/webdriver/extensions/android/display.py index 28abdcbb..4ee29ba7 100644 --- a/appium/webdriver/extensions/android/display.py +++ b/appium/webdriver/extensions/android/display.py @@ -12,18 +12,16 @@ # See the License for the specific language governing permissions and # limitations under the License. -from selenium.common.exceptions import UnknownMethodException - from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from appium.webdriver.mobilecommand import MobileCommand as Command -class Display(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class Display(CanExecuteCommands, CanExecuteScripts): def get_display_density(self) -> int: """Get the display density, Android only + Requires the Appium driver to support the `mobile: getDisplayDensity` execute method. + Returns: The display density of the Android device(dpi) @@ -34,15 +32,4 @@ def get_display_density(self) -> int: int: The display density """ ext_name = 'mobile: getDisplayDensity' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name) - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.GET_DISPLAY_DENSITY)['value'] - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.GET_DISPLAY_DENSITY, - 'GET', - '/session/$sessionId/appium/device/display_density', - ) + return self.execute_script(ext_name) diff --git a/appium/webdriver/extensions/android/gsm.py b/appium/webdriver/extensions/android/gsm.py index ce093c4a..56aedbd5 100644 --- a/appium/webdriver/extensions/android/gsm.py +++ b/appium/webdriver/extensions/android/gsm.py @@ -123,6 +123,3 @@ def set_gsm_voice(self, state: str) -> Self: args = {'state': state} self.execute_script(ext_name, args) return self - - def _add_commands(self) -> None: - pass diff --git a/appium/webdriver/extensions/android/network.py b/appium/webdriver/extensions/android/network.py index f3de8247..ad039104 100644 --- a/appium/webdriver/extensions/android/network.py +++ b/appium/webdriver/extensions/android/network.py @@ -48,6 +48,11 @@ def network_connection(self) -> int: This API only works reliably on emulators (any version) and real devices since API level 31. + + Requires the Appium driver to support the `mobile: getConnectivity` execute method. + + Returns: + The current network connection bitmask """ ext_name = 'mobile: getConnectivity' result_map = self.execute_script(ext_name) @@ -81,11 +86,14 @@ def set_network_connection(self, connection_type: int) -> int: This API only works reliably on emulators (any version) and real devices since API level 31. + Requires the Appium driver to support the `mobile: setConnectivity` and + `mobile: getConnectivity` execute methods. + Args: connection_type: a member of the enum `appium.webdriver.ConnectionType` - Return: - int: Set network connection type + Returns: + The current network connection bitmask after applying the change """ ext_name = 'mobile: setConnectivity' self.execute_script( @@ -103,6 +111,9 @@ def toggle_wifi(self) -> Self: This API only works reliably on emulators (any version) and real devices since API level 31. + Requires the Appium driver to support the `mobile: getConnectivity` and + `mobile: setConnectivity` execute methods. + Returns: Union['WebDriver', 'Network']: Self instance """ @@ -115,6 +126,8 @@ def set_network_speed(self, speed_type: str) -> Self: Android Emulator only. + Requires the Appium driver to support the `mobile: networkSpeed` execute method. + Args: speed_type: The network speed type. A member of the const appium.webdriver.extensions.android.network.NetSpeed. @@ -134,6 +147,3 @@ def set_network_speed(self, speed_type: str) -> Self: ext_name = 'mobile: networkSpeed' self.execute_script(ext_name, {'speed': speed_type}) return self - - def _add_commands(self) -> None: - pass diff --git a/appium/webdriver/extensions/android/performance.py b/appium/webdriver/extensions/android/performance.py index f5781cf3..97acddcd 100644 --- a/appium/webdriver/extensions/android/performance.py +++ b/appium/webdriver/extensions/android/performance.py @@ -14,15 +14,11 @@ from typing import Dict, List, Union -from selenium.common.exceptions import UnknownMethodException - from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from appium.webdriver.mobilecommand import MobileCommand as Command -class Performance(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class Performance(CanExecuteCommands, CanExecuteScripts): def get_performance_data( self, package_name: str, data_type: str, data_read_timeout: Union[int, None] = None ) -> List[List[str]]: @@ -31,12 +27,15 @@ def get_performance_data( Android only. + Requires the Appium driver to support the `mobile: getPerformanceData` execute method. + Args: package_name: The package name of the application data_type: The type of system state which wants to read. It should be one of the supported performance data types. Check :func:`.get_performance_data_types` for supported types - data_read_timeout: The number of attempts to read + data_read_timeout: Legacy parameter retained for compatibility; ignored by + `mobile: getPerformanceData` Usage: self.driver.get_performance_data('my.app.package', 'cpuinfo', 5) @@ -46,19 +45,15 @@ def get_performance_data( """ ext_name = 'mobile: getPerformanceData' args: Dict[str, Union[str, int]] = {'packageName': package_name, 'dataType': data_type} - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name, args) - except UnknownMethodException: - # TODO: Remove the fallback - if data_read_timeout is not None: - args['dataReadTimeout'] = data_read_timeout - return self.mark_extension_absence(ext_name).execute(Command.GET_PERFORMANCE_DATA, args)['value'] + return self.execute_script(ext_name, args) def get_performance_data_types(self) -> List[str]: """Returns the information types of the system state which is supported to read as like cpu, memory, network traffic, and battery. Android only. + Requires the Appium driver to support the `mobile: getPerformanceDataTypes` execute method. + Usage: self.driver.get_performance_data_types() @@ -66,20 +61,4 @@ def get_performance_data_types(self) -> List[str]: Available data types """ ext_name = 'mobile: getPerformanceDataTypes' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name) - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.GET_PERFORMANCE_DATA_TYPES)['value'] - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.GET_PERFORMANCE_DATA, - 'POST', - '/session/$sessionId/appium/getPerformanceData', - ) - self.command_executor.add_command( - Command.GET_PERFORMANCE_DATA_TYPES, - 'POST', - '/session/$sessionId/appium/performanceData/types', - ) + return self.execute_script(ext_name) diff --git a/appium/webdriver/extensions/android/power.py b/appium/webdriver/extensions/android/power.py index 537ab680..7b8b574e 100644 --- a/appium/webdriver/extensions/android/power.py +++ b/appium/webdriver/extensions/android/power.py @@ -12,16 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -from selenium.common.exceptions import UnknownMethodException from typing_extensions import Self from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from appium.webdriver.mobilecommand import MobileCommand as Command -class Power(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class Power(CanExecuteCommands, CanExecuteScripts): AC_OFF, AC_ON = 'off', 'on' def set_power_capacity(self, percent: int) -> Self: @@ -29,6 +26,8 @@ def set_power_capacity(self, percent: int) -> Self: Android only. + Requires the Appium driver to support the `mobile: powerCapacity` execute method. + Args: percent: The power capacity to be set. Can be set from 0 to 100 @@ -40,11 +39,7 @@ def set_power_capacity(self, percent: int) -> Self: """ ext_name = 'mobile: powerCapacity' args = {'percent': percent} - try: - self.assert_extension_exists(ext_name).execute_script(ext_name, args) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.SET_POWER_CAPACITY, args) + self.execute_script(ext_name, args) return self def set_power_ac(self, ac_state: str) -> Self: @@ -52,6 +47,8 @@ def set_power_ac(self, ac_state: str) -> Self: Android only. + Requires the Appium driver to support the `mobile: powerAC` execute method. + Args: ac_state: The power ac state to be set. Use `Power.AC_OFF`, `Power.AC_ON` @@ -64,17 +61,5 @@ def set_power_ac(self, ac_state: str) -> Self: """ ext_name = 'mobile: powerAC' args = {'state': ac_state} - try: - self.assert_extension_exists(ext_name).execute_script(ext_name, args) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.SET_POWER_AC, args) + self.execute_script(ext_name, args) return self - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.SET_POWER_CAPACITY, - 'POST', - '/session/$sessionId/appium/device/power_capacity', - ) - self.command_executor.add_command(Command.SET_POWER_AC, 'POST', '/session/$sessionId/appium/device/power_ac') diff --git a/appium/webdriver/extensions/android/sms.py b/appium/webdriver/extensions/android/sms.py index f5769c56..c4ada1f5 100644 --- a/appium/webdriver/extensions/android/sms.py +++ b/appium/webdriver/extensions/android/sms.py @@ -12,21 +12,20 @@ # See the License for the specific language governing permissions and # limitations under the License. -from selenium.common.exceptions import UnknownMethodException from typing_extensions import Self from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from appium.webdriver.mobilecommand import MobileCommand as Command -class Sms(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class Sms(CanExecuteCommands, CanExecuteScripts): def send_sms(self, phone_number: str, message: str) -> Self: """Emulate send SMS event on the connected emulator. Android only. + Requires the Appium driver to support the `mobile: sendSms` execute method. + Args: phone_number: The phone number of message sender message: The message to send @@ -39,12 +38,5 @@ def send_sms(self, phone_number: str, message: str) -> Self: """ ext_name = 'mobile: sendSms' args = {'phoneNumber': phone_number, 'message': message} - try: - self.assert_extension_exists(ext_name).execute_script(ext_name, args) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.SEND_SMS, args) + self.execute_script(ext_name, args) return self - - def _add_commands(self) -> None: - self.command_executor.add_command(Command.SEND_SMS, 'POST', '/session/$sessionId/appium/device/send_sms') diff --git a/appium/webdriver/extensions/android/system_bars.py b/appium/webdriver/extensions/android/system_bars.py index a02c21f8..30cb9cd2 100644 --- a/appium/webdriver/extensions/android/system_bars.py +++ b/appium/webdriver/extensions/android/system_bars.py @@ -14,20 +14,18 @@ from typing import Dict, Union -from selenium.common.exceptions import UnknownMethodException - from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from appium.webdriver.mobilecommand import MobileCommand as Command -class SystemBars(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class SystemBars(CanExecuteCommands, CanExecuteScripts): def get_system_bars(self) -> Dict[str, Dict[str, Union[int, bool]]]: """Retrieve visibility and bounds information of the status and navigation bars. Android only. + Requires the Appium driver to support the `mobile: getSystemBars` execute method. + Returns: A dictionary whose keys are - statusBar @@ -44,15 +42,4 @@ def get_system_bars(self) -> Dict[str, Dict[str, Union[int, bool]]]: - height """ ext_name = 'mobile: getSystemBars' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name) - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.GET_SYSTEM_BARS)['value'] - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.GET_SYSTEM_BARS, - 'GET', - '/session/$sessionId/appium/device/system_bars', - ) + return self.execute_script(ext_name) diff --git a/appium/webdriver/extensions/applications.py b/appium/webdriver/extensions/applications.py index a6782bfa..dc729f40 100644 --- a/appium/webdriver/extensions/applications.py +++ b/appium/webdriver/extensions/applications.py @@ -190,6 +190,3 @@ def app_strings(self, language: Union[str, None] = None, string_file: Union[str, if string_file is not None: data['stringFile'] = string_file return self.execute_script(ext_name, data) - - def _add_commands(self) -> None: - pass diff --git a/appium/webdriver/extensions/clipboard.py b/appium/webdriver/extensions/clipboard.py index f5354f2e..c5a6e544 100644 --- a/appium/webdriver/extensions/clipboard.py +++ b/appium/webdriver/extensions/clipboard.py @@ -15,23 +15,21 @@ import base64 from typing import Optional -from selenium.common.exceptions import UnknownMethodException from typing_extensions import Self from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence from appium.webdriver.clipboard_content_type import ClipboardContentType -from ..mobilecommand import MobileCommand as Command - -class Clipboard(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class Clipboard(CanExecuteCommands, CanExecuteScripts): def set_clipboard( self, content: bytes, content_type: str = ClipboardContentType.PLAINTEXT, label: Optional[str] = None ) -> Self: """Set the content of the system clipboard + Requires the Appium driver to support the `mobile: setClipboard` execute method. + Args: content: The content to be set as bytearray string content_type: One of ClipboardContentType items. Only ClipboardContentType.PLAINTEXT @@ -48,16 +46,14 @@ def set_clipboard( } if label: options['label'] = label - try: - self.assert_extension_exists(ext_name).execute_script(ext_name, options) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.SET_CLIPBOARD, options) + self.execute_script(ext_name, options) return self def set_clipboard_text(self, text: str, label: Optional[str] = None) -> Self: """Copies the given text to the system clipboard + Requires the Appium driver to support the `mobile: setClipboard` execute method. + Args: text: The text to be set label:label argument, which only works for Android @@ -70,6 +66,8 @@ def set_clipboard_text(self, text: str, label: Optional[str] = None) -> Self: def get_clipboard(self, content_type: str = ClipboardContentType.PLAINTEXT) -> bytes: """Receives the content of the system clipboard + Requires the Appium driver to support the `mobile: getClipboard` execute method. + Args: content_type: One of ClipboardContentType items. Only ClipboardContentType.PLAINTEXT is supported on Android @@ -79,29 +77,15 @@ def get_clipboard(self, content_type: str = ClipboardContentType.PLAINTEXT) -> b """ ext_name = 'mobile: getClipboard' options = {'contentType': content_type} - try: - base64_str = self.assert_extension_exists(ext_name).execute_script(ext_name, options) - except UnknownMethodException: - # TODO: Remove the fallback - base64_str = self.mark_extension_absence(ext_name).execute(Command.GET_CLIPBOARD, options)['value'] + base64_str = self.execute_script(ext_name, options) return base64.b64decode(base64_str) def get_clipboard_text(self) -> str: """Receives the text of the system clipboard + Requires the Appium driver to support the `mobile: getClipboard` execute method. + Returns: The actual clipboard text or an empty string if the clipboard is empty """ return self.get_clipboard(ClipboardContentType.PLAINTEXT).decode('UTF-8') - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.SET_CLIPBOARD, - 'POST', - '/session/$sessionId/appium/device/set_clipboard', - ) - self.command_executor.add_command( - Command.GET_CLIPBOARD, - 'POST', - '/session/$sessionId/appium/device/get_clipboard', - ) diff --git a/appium/webdriver/extensions/device_time.py b/appium/webdriver/extensions/device_time.py index 22ac3c25..ad79e49c 100644 --- a/appium/webdriver/extensions/device_time.py +++ b/appium/webdriver/extensions/device_time.py @@ -14,33 +14,28 @@ from typing import Optional -from selenium.common.exceptions import UnknownMethodException - from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence - -from ..mobilecommand import MobileCommand as Command -class DeviceTime(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class DeviceTime(CanExecuteCommands, CanExecuteScripts): @property def device_time(self) -> str: """Returns the date and time from the device. + Requires the Appium driver to support the `mobile: getDeviceTime` execute method. + Return: str: The date and time """ ext_name = 'mobile: getDeviceTime' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name) - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.GET_DEVICE_TIME_GET, {})['value'] + return self.execute_script(ext_name) def get_device_time(self, format: Optional[str] = None) -> str: """Returns the date and time from the device. + Requires the Appium driver to support the `mobile: getDeviceTime` execute method. + Args: format: The set of format specifiers. Read https://momentjs.com/docs/ to get the full list of supported datetime format specifiers. @@ -57,19 +52,4 @@ def get_device_time(self, format: Optional[str] = None) -> str: ext_name = 'mobile: getDeviceTime' if format is None: return self.device_time - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name, {'format': format}) - except UnknownMethodException: - return self.mark_extension_absence(ext_name).execute(Command.GET_DEVICE_TIME_POST, {'format': format})['value'] - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.GET_DEVICE_TIME_GET, - 'GET', - '/session/$sessionId/appium/device/system_time', - ) - self.command_executor.add_command( - Command.GET_DEVICE_TIME_POST, - 'POST', - '/session/$sessionId/appium/device/system_time', - ) + return self.execute_script(ext_name, {'format': format}) diff --git a/appium/webdriver/extensions/hw_actions.py b/appium/webdriver/extensions/hw_actions.py index b6bbb468..4f80bcab 100644 --- a/appium/webdriver/extensions/hw_actions.py +++ b/appium/webdriver/extensions/hw_actions.py @@ -14,19 +14,17 @@ from typing import Optional -from selenium.common.exceptions import UnknownMethodException from typing_extensions import Self from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from ..mobilecommand import MobileCommand as Command - -class HardwareActions(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class HardwareActions(CanExecuteCommands, CanExecuteScripts): def lock(self, seconds: Optional[int] = None) -> Self: - """Lock the device. No changes are made if the device is already unlocked. + """Lock the device. No changes are made if the device is already locked. + + Requires the Appium driver to support the `mobile: lock` execute method. Args: seconds: The duration to lock the device, in seconds. @@ -39,54 +37,44 @@ def lock(self, seconds: Optional[int] = None) -> Self: """ ext_name = 'mobile: lock' args = {'seconds': seconds or 0} - try: - self.assert_extension_exists(ext_name).execute_script(ext_name, args) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.LOCK, args) + self.execute_script(ext_name, args) return self def unlock(self) -> Self: - """Unlock the device. No changes are made if the device is already locked. + """Unlock the device. No changes are made if the device is already unlocked. + + Requires the Appium driver to support the `mobile: isLocked` and `mobile: unlock` execute methods. Returns: Union['WebDriver', 'HardwareActions']: Self instance """ ext_name = 'mobile: unlock' - try: - if not self.assert_extension_exists(ext_name).execute_script('mobile: isLocked'): - return self - self.execute_script(ext_name) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.UNLOCK) + if not self.execute_script('mobile: isLocked'): + return self + self.execute_script(ext_name) return self def is_locked(self) -> bool: """Checks whether the device is locked. + Requires the Appium driver to support the `mobile: isLocked` execute method. + Returns: `True` if the device is locked """ ext_name = 'mobile: isLocked' - try: - return self.assert_extension_exists(ext_name).execute_script('mobile: isLocked') - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.IS_LOCKED)['value'] + return self.execute_script(ext_name) def shake(self) -> Self: """Shake the device. + Requires the Appium driver to support the `mobile: shake` execute method. + Returns: Union['WebDriver', 'HardwareActions']: Self instance """ ext_name = 'mobile: shake' - try: - self.assert_extension_exists(ext_name).execute_script(ext_name) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.SHAKE) + self.execute_script(ext_name) return self def touch_id(self, match: bool) -> Self: @@ -118,32 +106,17 @@ def toggle_touch_id_enrollment(self) -> Self: return self def finger_print(self, finger_id: int) -> Self: - """Authenticate users by using their finger print scans on supported Android emulators. + """Authenticate users using a fingerprint scan on supported Android emulators. + + Requires the Appium driver to support the `mobile: fingerprint` execute method. Args: - finger_id: Finger prints stored in Android Keystore system (from 1 to 10) + finger_id: Fingerprint identifier stored in the Android Keystore system (from 1 to 10) + + Returns: + Union['WebDriver', 'HardwareActions']: Self instance """ ext_name = 'mobile: fingerprint' args = {'fingerprintId': finger_id} - try: - self.assert_extension_exists(ext_name).execute_script(ext_name, args) - except UnknownMethodException: - self.mark_extension_absence(ext_name).execute(Command.FINGER_PRINT, args) + self.execute_script(ext_name, args) return self - - def _add_commands(self) -> None: - self.command_executor.add_command(Command.LOCK, 'POST', '/session/$sessionId/appium/device/lock') - self.command_executor.add_command(Command.UNLOCK, 'POST', '/session/$sessionId/appium/device/unlock') - self.command_executor.add_command(Command.IS_LOCKED, 'POST', '/session/$sessionId/appium/device/is_locked') - self.command_executor.add_command(Command.SHAKE, 'POST', '/session/$sessionId/appium/device/shake') - self.command_executor.add_command(Command.TOUCH_ID, 'POST', '/session/$sessionId/appium/simulator/touch_id') - self.command_executor.add_command( - Command.TOGGLE_TOUCH_ID_ENROLLMENT, - 'POST', - '/session/$sessionId/appium/simulator/toggle_touch_id_enrollment', - ) - self.command_executor.add_command( - Command.FINGER_PRINT, - 'POST', - '/session/$sessionId/appium/device/finger_print', - ) diff --git a/appium/webdriver/extensions/keyboard.py b/appium/webdriver/extensions/keyboard.py index 4640b116..cae8ee81 100644 --- a/appium/webdriver/extensions/keyboard.py +++ b/appium/webdriver/extensions/keyboard.py @@ -12,62 +12,45 @@ # See the License for the specific language governing permissions and # limitations under the License. -from typing import Dict, Optional +from typing import Optional -from selenium.common.exceptions import UnknownMethodException from typing_extensions import Self from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from ..mobilecommand import MobileCommand as Command - -class Keyboard(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class Keyboard(CanExecuteCommands, CanExecuteScripts): def hide_keyboard(self, key_name: Optional[str] = None, key: Optional[str] = None, strategy: Optional[str] = None) -> Self: """Hides the software keyboard on the device. - In iOS, use `key_name` to press - a particular key, or `strategy`. In Android, no parameters are used. + On iOS, use `key_name` or `key` to provide a keyboard key name. + On Android, no parameters are used. `strategy` is retained for compatibility and ignored. + + Requires the Appium driver to support the `mobile: hideKeyboard` execute method. Args: - key_name: key to press - key: - strategy: strategy for closing the keyboard (e.g., `tapOutside`) + key_name: Keyboard key name to use on iOS + key: Alias for `key_name` + strategy: Legacy argument retained for compatibility; ignored by `mobile: hideKeyboard` Returns: Union['WebDriver', 'Keyboard']: Self instance """ ext_name = 'mobile: hideKeyboard' - try: - self.assert_extension_exists(ext_name).execute_script( - ext_name, {**({'keys': [key or key_name]} if key or key_name else {})} - ) - except UnknownMethodException: - # TODO: Remove the fallback - data: Dict[str, Optional[str]] = {} - if key_name is not None: - data['keyName'] = key_name - elif key is not None: - data['key'] = key - elif strategy is None: - strategy = 'tapOutside' - data['strategy'] = strategy - self.mark_extension_absence(ext_name).execute(Command.HIDE_KEYBOARD, data) + self.execute_script(ext_name, {**({'keys': [key or key_name]} if key or key_name else {})}) return self def is_keyboard_shown(self) -> bool: """Attempts to detect whether a software keyboard is present + Requires the Appium driver to support the `mobile: isKeyboardShown` execute method. + Returns: `True` if keyboard is shown """ ext_name = 'mobile: isKeyboardShown' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name) - except UnknownMethodException: - return self.mark_extension_absence(ext_name).execute(Command.IS_KEYBOARD_SHOWN)['value'] + return self.execute_script(ext_name) def keyevent(self, keycode: int, metastate: Optional[int] = None) -> Self: """Sends a keycode to the device. @@ -75,6 +58,8 @@ def keyevent(self, keycode: int, metastate: Optional[int] = None) -> Self: Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html. + Requires the Appium driver to support the `mobile: pressKey` execute method. + Args: keycode: the keycode to be sent to the device metastate: meta information about the keycode being sent @@ -90,6 +75,8 @@ def press_keycode(self, keycode: int, metastate: Optional[int] = None, flags: Op Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html. + Requires the Appium driver to support the `mobile: pressKey` execute method. + Args: keycode: the keycode to be sent to the device metastate: meta information about the keycode being sent @@ -104,11 +91,7 @@ def press_keycode(self, keycode: int, metastate: Optional[int] = None, flags: Op args['metastate'] = metastate if flags is not None: args['flags'] = flags - try: - self.assert_extension_exists(ext_name).execute_script(ext_name, args) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.PRESS_KEYCODE, args) + self.execute_script(ext_name, args) return self def long_press_keycode(self, keycode: int, metastate: Optional[int] = None, flags: Optional[int] = None) -> Self: @@ -117,6 +100,8 @@ def long_press_keycode(self, keycode: int, metastate: Optional[int] = None, flag Android only. Possible keycodes can be found in http://developer.android.com/reference/android/view/KeyEvent.html. + Requires the Appium driver to support the `mobile: pressKey` execute method. + Args: keycode: the keycode to be sent to the device metastate: meta information about the keycode being sent @@ -131,38 +116,11 @@ def long_press_keycode(self, keycode: int, metastate: Optional[int] = None, flag args['metastate'] = metastate if flags is not None: args['flags'] = flags - try: - self.assert_extension_exists(ext_name).execute_script( - ext_name, - { - **args, - 'isLongPress': True, - }, - ) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute(Command.LONG_PRESS_KEYCODE, args) - return self - - def _add_commands(self) -> None: - self.command_executor.add_command( - Command.HIDE_KEYBOARD, - 'POST', - '/session/$sessionId/appium/device/hide_keyboard', - ) - self.command_executor.add_command( - Command.IS_KEYBOARD_SHOWN, - 'GET', - '/session/$sessionId/appium/device/is_keyboard_shown', - ) - self.command_executor.add_command(Command.KEY_EVENT, 'POST', '/session/$sessionId/appium/device/keyevent') - self.command_executor.add_command( - Command.PRESS_KEYCODE, - 'POST', - '/session/$sessionId/appium/device/press_keycode', - ) - self.command_executor.add_command( - Command.LONG_PRESS_KEYCODE, - 'POST', - '/session/$sessionId/appium/device/long_press_keycode', + self.execute_script( + ext_name, + { + **args, + 'isLongPress': True, + }, ) + return self diff --git a/appium/webdriver/extensions/remote_fs.py b/appium/webdriver/extensions/remote_fs.py index 5ccebd37..9139cd4c 100644 --- a/appium/webdriver/extensions/remote_fs.py +++ b/appium/webdriver/extensions/remote_fs.py @@ -15,20 +15,19 @@ import base64 from typing import Optional -from selenium.common.exceptions import InvalidArgumentException, UnknownMethodException +from selenium.common.exceptions import InvalidArgumentException from typing_extensions import Self from appium.protocols.webdriver.can_execute_commands import CanExecuteCommands from appium.protocols.webdriver.can_execute_scripts import CanExecuteScripts -from appium.protocols.webdriver.can_remember_extension_presence import CanRememberExtensionPresence -from ..mobilecommand import MobileCommand as Command - -class RemoteFS(CanExecuteCommands, CanExecuteScripts, CanRememberExtensionPresence): +class RemoteFS(CanExecuteCommands, CanExecuteScripts): def pull_file(self, path: str) -> str: """Retrieves the file at `path`. + Requires the Appium driver to support the `mobile: pullFile` execute method. + Args: path: the path to the file on the device @@ -36,15 +35,13 @@ def pull_file(self, path: str) -> str: The file's contents encoded as Base64. """ ext_name = 'mobile: pullFile' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name, {'remotePath': path}) - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.PULL_FILE, {'path': path})['value'] + return self.execute_script(ext_name, {'remotePath': path}) def pull_folder(self, path: str) -> str: """Retrieves a folder at `path`. + Requires the Appium driver to support the `mobile: pullFolder` execute method. + Args: path: the path to the folder on the device @@ -52,21 +49,19 @@ def pull_folder(self, path: str) -> str: The folder's contents zipped and encoded as Base64. """ ext_name = 'mobile: pullFolder' - try: - return self.assert_extension_exists(ext_name).execute_script(ext_name, {'remotePath': path}) - except UnknownMethodException: - # TODO: Remove the fallback - return self.mark_extension_absence(ext_name).execute(Command.PULL_FOLDER, {'path': path})['value'] + return self.execute_script(ext_name, {'remotePath': path}) def push_file(self, destination_path: str, base64data: Optional[str] = None, source_path: Optional[str] = None) -> Self: - """Puts the data from the file at `source_path`, encoded as Base64, in the file specified as `path`. + """Puts the data from the file at `source_path`, encoded as Base64, at `destination_path`. - Specify either `base64data` or `source_path`, if both specified default to `source_path` + Specify either `base64data` or `source_path`. If both are provided, `source_path` takes precedence. + + Requires the Appium driver to support the `mobile: pushFile` execute method. Args: destination_path: the location on the device/simulator where the local file contents should be saved base64data: file contents, encoded as Base64, to be written - to the file on the device/simulator + to the file on the device/simulator source_path: local file path for the file to be loaded on device Returns: @@ -85,26 +80,11 @@ def push_file(self, destination_path: str, base64data: Optional[str] = None, sou base64data = base64.b64encode(file_data).decode('utf-8') ext_name = 'mobile: pushFile' - try: - self.assert_extension_exists(ext_name).execute_script( - ext_name, - { - 'remotePath': destination_path, - 'payload': base64data, - }, - ) - except UnknownMethodException: - # TODO: Remove the fallback - self.mark_extension_absence(ext_name).execute( - Command.PUSH_FILE, - { - 'path': destination_path, - 'data': base64data, - }, - ) + self.execute_script( + ext_name, + { + 'remotePath': destination_path, + 'payload': base64data, + }, + ) return self - - def _add_commands(self) -> None: - self.command_executor.add_command(Command.PULL_FILE, 'POST', '/session/$sessionId/appium/device/pull_file') - self.command_executor.add_command(Command.PULL_FOLDER, 'POST', '/session/$sessionId/appium/device/pull_folder') - self.command_executor.add_command(Command.PUSH_FILE, 'POST', '/session/$sessionId/appium/device/push_file') diff --git a/test/unit/webdriver/device/activities_test.py b/test/unit/webdriver/device/activities_test.py index acfe3d2e..15df9b78 100644 --- a/test/unit/webdriver/device/activities_test.py +++ b/test/unit/webdriver/device/activities_test.py @@ -21,11 +21,6 @@ class TestWebDriverActivities: @httpretty.activate def test_current_activity(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890/appium/device/current_activity'), - body='{"value": ".ExampleActivity"}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -36,11 +31,6 @@ def test_current_activity(self): @httpretty.activate def test_wait_activity(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890/appium/device/current_activity'), - body='{"value": ".ExampleActivity"}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), diff --git a/test/unit/webdriver/device/clipboard_test.py b/test/unit/webdriver/device/clipboard_test.py index 3708b2a3..d5a33a2c 100644 --- a/test/unit/webdriver/device/clipboard_test.py +++ b/test/unit/webdriver/device/clipboard_test.py @@ -22,9 +22,6 @@ class TestWebDriverClipboard: @httpretty.activate def test_set_clipboard_with_url(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/set_clipboard'), body='{"value": ""}' - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -40,9 +37,6 @@ def test_set_clipboard_with_url(self): @httpretty.activate def test_set_clipboard_text(self): driver = ios_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/set_clipboard'), body='{"value": ""}' - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), diff --git a/test/unit/webdriver/device/device_time_test.py b/test/unit/webdriver/device/device_time_test.py index 4d7e7211..98d01336 100644 --- a/test/unit/webdriver/device/device_time_test.py +++ b/test/unit/webdriver/device/device_time_test.py @@ -21,11 +21,6 @@ class TestWebDriverDeviceTime: @httpretty.activate def test_device_time(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890/appium/device/system_time'), - body='{"value": "2019-01-05T14:46:44+09:00"}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -36,11 +31,6 @@ def test_device_time(self): @httpretty.activate def test_get_device_time(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890/appium/device/system_time'), - body='{"value": "2019-01-05T14:46:44+09:00"}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -51,11 +41,6 @@ def test_get_device_time(self): @httpretty.activate def test_get_formatted_device_time(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/system_time'), - body='{"value": "2019-01-08"}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -64,4 +49,5 @@ def test_get_formatted_device_time(self): assert driver.get_device_time('YYYY-MM-DD') == '2019-01-08' d = get_httpretty_request_body(httpretty.last_request()) - assert d.get('format', d['args'][0]['format']) == 'YYYY-MM-DD' + assert d['script'] == 'mobile: getDeviceTime' + assert d['args'][0]['format'] == 'YYYY-MM-DD' diff --git a/test/unit/webdriver/device/display_test.py b/test/unit/webdriver/device/display_test.py index 96cc0d01..cc93c86a 100644 --- a/test/unit/webdriver/device/display_test.py +++ b/test/unit/webdriver/device/display_test.py @@ -21,8 +21,5 @@ class TestWebDriverDisplay: @httpretty.activate def test_get_display_density(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.GET, appium_command('/session/1234567890/appium/device/display_density'), body='{"value": 560}' - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": 560}') assert driver.get_display_density() == 560 diff --git a/test/unit/webdriver/device/fingerprint_test.py b/test/unit/webdriver/device/fingerprint_test.py index 83a992ef..93b02784 100644 --- a/test/unit/webdriver/device/fingerprint_test.py +++ b/test/unit/webdriver/device/fingerprint_test.py @@ -22,11 +22,6 @@ class TestWebDriverFingerprint: @httpretty.activate def test_finger_print(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/finger_print'), - # body is None - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -36,4 +31,5 @@ def test_finger_print(self): assert isinstance(driver.finger_print(1), WebDriver) d = get_httpretty_request_body(httpretty.last_request()) - assert d.get('fingerprintId', d['args'][0]['fingerprintId']) == 1 + assert d['script'] == 'mobile: fingerprint' + assert d['args'][0]['fingerprintId'] == 1 diff --git a/test/unit/webdriver/device/keyboard_test.py b/test/unit/webdriver/device/keyboard_test.py index 5ec55a2a..33f31a53 100644 --- a/test/unit/webdriver/device/keyboard_test.py +++ b/test/unit/webdriver/device/keyboard_test.py @@ -23,51 +23,37 @@ class TestWebDriverKeyboardAndroid: @httpretty.activate def test_hide_keyboard(self): driver = android_w3c_driver() - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/hide_keyboard')) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync')) assert isinstance(driver.hide_keyboard(), WebDriver) @httpretty.activate def test_press_keycode(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/press_keycode'), body='{"value": "86"}' - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": "86"}') driver.press_keycode(86) d = get_httpretty_request_body((httpretty.last_request())) - assert d.get('keycode', d['args'][0]['keycode']) == 86 + assert d['script'] == 'mobile: pressKey' + assert d['args'][0]['keycode'] == 86 @httpretty.activate def test_long_press_keycode(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/long_press_keycode'), - body='{"value": "86"}', - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": "86"}') driver.long_press_keycode(86) d = get_httpretty_request_body((httpretty.last_request())) - assert d.get('keycode', d['args'][0]['keycode']) == 86 + assert d['script'] == 'mobile: pressKey' + assert d['args'][0]['keycode'] == 86 + assert d['args'][0]['isLongPress'] is True @httpretty.activate def test_keyevent(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/keyevent'), body='{keycode: 86}' - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": "86"}') assert isinstance(driver.keyevent(86), WebDriver) @httpretty.activate def test_press_keycode_with_flags(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/press_keycode'), - body='{keycode: 86, metastate: 2097153, flags: 44}', - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync')) # metastate is META_SHIFT_ON and META_NUM_LOCK_ON # flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE, FLAG_FROM_SYSTEM @@ -83,11 +69,6 @@ def test_press_keycode_with_flags(self): @httpretty.activate def test_long_press_keycode_with_flags(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/long_press_keycode'), - body='{keycode: 86, metastate: 2097153, flags: 44}', - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync')) # metastate is META_SHIFT_ON and META_NUM_LOCK_ON # flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE, FLAG_FROM_SYSTEM diff --git a/test/unit/webdriver/device/lock_test.py b/test/unit/webdriver/device/lock_test.py index 4c959dae..1cd89c41 100644 --- a/test/unit/webdriver/device/lock_test.py +++ b/test/unit/webdriver/device/lock_test.py @@ -22,94 +22,74 @@ class TestWebDriverLockAndroid: @httpretty.activate def test_lock(self): driver = android_w3c_driver() - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}') httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}') driver.lock(1) d = get_httpretty_request_body(httpretty.last_request()) - assert d.get('seconds', d['args'][0]['seconds']) == 1 + assert d['script'] == 'mobile: lock' + assert d['args'][0]['seconds'] == 1 @httpretty.activate def test_lock_no_args(self): driver = android_w3c_driver() - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}') httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}') driver.lock() @httpretty.activate def test_islocked_false(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": false}' - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": false}') assert driver.is_locked() is False @httpretty.activate def test_islocked_true(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": true}' - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}') assert driver.is_locked() is True @httpretty.activate def test_unlock(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/unlock'), - ) - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync')) + httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}') assert isinstance(driver.unlock(), WebDriver) + assert get_httpretty_request_body(httpretty.last_request())['script'] == 'mobile: unlock' class TestWebDriverLockIOS: @httpretty.activate def test_lock(self): driver = ios_w3c_driver() - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}') httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}') driver.lock(1) d = get_httpretty_request_body(httpretty.last_request()) - assert d.get('seconds', d['args'][0]['seconds']) == 1 + assert d['script'] == 'mobile: lock' + assert d['args'][0]['seconds'] == 1 @httpretty.activate def test_lock_no_args(self): driver = ios_w3c_driver() - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/appium/device/lock'), body='{"value": ""}') httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": ""}') driver.lock() @httpretty.activate def test_islocked_false(self): driver = ios_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": false}' - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": false}') assert driver.is_locked() is False @httpretty.activate def test_islocked_true(self): driver = ios_w3c_driver() - httpretty.register_uri( - httpretty.POST, appium_command('/session/1234567890/appium/device/is_locked'), body='{"value": true}' - ) httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}') assert driver.is_locked() is True @httpretty.activate def test_unlock(self): driver = ios_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/unlock'), - ) - httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync')) + httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/execute/sync'), body='{"value": true}') assert isinstance(driver.unlock(), WebDriver) + assert get_httpretty_request_body(httpretty.last_request())['script'] == 'mobile: unlock' @httpretty.activate def test_touch_id(self): diff --git a/test/unit/webdriver/device/power_test.py b/test/unit/webdriver/device/power_test.py index 2d99a4a5..ea5fe1dc 100644 --- a/test/unit/webdriver/device/power_test.py +++ b/test/unit/webdriver/device/power_test.py @@ -23,10 +23,6 @@ class TestWebDriverPower: @httpretty.activate def test_set_power_capacity(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/power_capacity'), - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -34,15 +30,12 @@ def test_set_power_capacity(self): assert isinstance(driver.set_power_capacity(50), WebDriver) d = get_httpretty_request_body(httpretty.last_request()) + assert d['script'] == 'mobile: powerCapacity' assert d['args'][0]['percent'] == 50 @httpretty.activate def test_set_power_ac(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/power_ac'), - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -50,4 +43,5 @@ def test_set_power_ac(self): assert isinstance(driver.set_power_ac(Power.AC_ON), WebDriver) d = get_httpretty_request_body(httpretty.last_request()) + assert d['script'] == 'mobile: powerAC' assert d['args'][0]['state'] == Power.AC_ON diff --git a/test/unit/webdriver/device/remote_fs_test.py b/test/unit/webdriver/device/remote_fs_test.py index 93148e66..f1fca0df 100644 --- a/test/unit/webdriver/device/remote_fs_test.py +++ b/test/unit/webdriver/device/remote_fs_test.py @@ -26,10 +26,6 @@ class TestWebDriverRemoteFs: @httpretty.activate def test_push_file(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/push_file'), - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -40,16 +36,13 @@ def test_push_file(self): assert isinstance(driver.push_file(dest_path, data), WebDriver) d = get_httpretty_request_body(httpretty.last_request()) - assert d.get('path', d['args'][0]['remotePath']) == dest_path - assert d.get('data', d['args'][0]['payload']) == str(data) + assert d['script'] == 'mobile: pushFile' + assert d['args'][0]['remotePath'] == dest_path + assert d['args'][0]['payload'] == str(data) @httpretty.activate def test_push_file_invalid_arg_exception_without_src_path_and_base64data(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/push_file'), - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -62,14 +55,6 @@ def test_push_file_invalid_arg_exception_without_src_path_and_base64data(self): @httpretty.activate def test_push_file_invalid_arg_exception_with_src_file_not_found(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/push_file'), - ) - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/push_file'), - ) dest_path = '/dest_path/to/file.txt' src_path = '/src_path/to/file.txt' @@ -79,11 +64,6 @@ def test_push_file_invalid_arg_exception_with_src_file_not_found(self): @httpretty.activate def test_pull_file(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/pull_file'), - body='{"value": "SGVsbG9Xb3JsZA=="}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -94,16 +74,12 @@ def test_pull_file(self): assert driver.pull_file(dest_path) == str(base64.b64encode(bytes('HelloWorld', 'utf-8')).decode('utf-8')) d = get_httpretty_request_body(httpretty.last_request()) - assert d.get('path', d['args'][0]['remotePath']) == dest_path + assert d['script'] == 'mobile: pullFile' + assert d['args'][0]['remotePath'] == dest_path @httpretty.activate def test_pull_folder(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/pull_folder'), - body='{"value": "base64EncodedZippedFolderData"}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -114,4 +90,5 @@ def test_pull_folder(self): assert driver.pull_folder(dest_path) == 'base64EncodedZippedFolderData' d = get_httpretty_request_body(httpretty.last_request()) - assert d.get('path', d['args'][0]['remotePath']) == dest_path + assert d['script'] == 'mobile: pullFolder' + assert d['args'][0]['remotePath'] == dest_path diff --git a/test/unit/webdriver/device/shake_test.py b/test/unit/webdriver/device/shake_test.py index b12d791a..8c796255 100644 --- a/test/unit/webdriver/device/shake_test.py +++ b/test/unit/webdriver/device/shake_test.py @@ -23,10 +23,6 @@ class TestWebDriverShake: @httpretty.activate def test_shake(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/shake'), - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), diff --git a/test/unit/webdriver/device/sms_test.py b/test/unit/webdriver/device/sms_test.py index 65e66e6b..a7200dca 100644 --- a/test/unit/webdriver/device/sms_test.py +++ b/test/unit/webdriver/device/sms_test.py @@ -22,10 +22,6 @@ class TestWebDriverSms: @httpretty.activate def test_send_sms(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/device/send_sms'), - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -33,5 +29,6 @@ def test_send_sms(self): assert isinstance(driver.send_sms('555-123-4567', 'Hey lol'), WebDriver) d = get_httpretty_request_body(httpretty.last_request()) + assert d['script'] == 'mobile: sendSms' assert d['args'][0]['phoneNumber'] == '555-123-4567' assert d['args'][0]['message'] == 'Hey lol' diff --git a/test/unit/webdriver/device/system_bars_test.py b/test/unit/webdriver/device/system_bars_test.py index 6d714c2d..3592c005 100644 --- a/test/unit/webdriver/device/system_bars_test.py +++ b/test/unit/webdriver/device/system_bars_test.py @@ -26,11 +26,6 @@ def test_get_system_bars(self): {"visible": true, "x": 0, "y": 0, "width": 1080, "height": 1920}, "navigationBar": {"visible": true, "x": 0, "y": 0, "width": 1080, "height": 126}}}""" - httpretty.register_uri( - httpretty.GET, - appium_command('/session/1234567890/appium/device/system_bars'), - body=body, - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), diff --git a/test/unit/webdriver/performance_test.py b/test/unit/webdriver/performance_test.py index 6bae8dd9..c21f720e 100644 --- a/test/unit/webdriver/performance_test.py +++ b/test/unit/webdriver/performance_test.py @@ -21,11 +21,6 @@ class TestWebDriverPerformance: @httpretty.activate def test_get_performance_data(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/getPerformanceData'), - body='{"value": [["user", "kernel"], ["2.5", "1.3"]]}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'), @@ -34,17 +29,13 @@ def test_get_performance_data(self): assert driver.get_performance_data('my.app.package', 'cpuinfo', 5) == [['user', 'kernel'], ['2.5', '1.3']] d = get_httpretty_request_body(httpretty.last_request()) + assert d['script'] == 'mobile: getPerformanceData' assert d['args'][0]['packageName'] == 'my.app.package' assert d['args'][0]['dataType'] == 'cpuinfo' @httpretty.activate def test_get_performance_data_types(self): driver = android_w3c_driver() - httpretty.register_uri( - httpretty.POST, - appium_command('/session/1234567890/appium/performanceData/types'), - body='{"value": ["cpuinfo", "memoryinfo", "batteryinfo", "networkinfo"]}', - ) httpretty.register_uri( httpretty.POST, appium_command('/session/1234567890/execute/sync'),