From aac9143d96fb873d29b221e32f47bb69b1245f38 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:44:27 +0000 Subject: [PATCH 01/19] chore(deps): update rubocop requirement from 1.72.2 to 1.73.0 Updates the requirements on [rubocop](https://github.com/rubocop/rubocop) to permit the latest version. - [Release notes](https://github.com/rubocop/rubocop/releases) - [Changelog](https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md) - [Commits](https://github.com/rubocop/rubocop/compare/v1.72.2...v1.73.0) --- updated-dependencies: - dependency-name: rubocop dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 4dd59e5e..dfa8f22b 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'minitest', '~> 5.0' gem 'minitest-reporters', '~> 1.1' gem 'parallel_tests' gem 'rake', '~> 13.0' -gem 'rubocop', '1.72.2' +gem 'rubocop', '1.73.0' gem 'simplecov' gem 'steep', '~> 1.9.3' gem 'webmock', '~> 3.25.0' From 868be4fbefc13f23ac838c8bb8818df5cfe00030 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 27 Feb 2025 00:14:12 -0800 Subject: [PATCH 02/19] fix rubocop --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index 85cdacc6..3833258a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -130,7 +130,7 @@ def ios(platform_name = :ios) platform_version = '17.4' wda_port = wda_local_port - real_device = ENV['REAL'] ? true : false + real_device = ENV['REAL'] || false cap = { caps: { # :desiredCapabilities is also available From 7321b324c995920bda710912fbb9628e8f3960d1 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 10:25:22 -0700 Subject: [PATCH 03/19] use app_state via mobile command --- lib/appium_lib_core/common/base/driver.rb | 1 - lib/appium_lib_core/common/device/app_state.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/appium_lib_core/common/base/driver.rb b/lib/appium_lib_core/common/base/driver.rb index afa1020d..f87a477c 100644 --- a/lib/appium_lib_core/common/base/driver.rb +++ b/lib/appium_lib_core/common/base/driver.rb @@ -732,7 +732,6 @@ def terminate_app(app_id, timeout: nil) # @driver.query_app_state("io.appium.bundle") #=> :not_running # def app_state(app_id) - # TODO: use mobile command in the background? @bridge.app_state(app_id) end alias query_app_state app_state diff --git a/lib/appium_lib_core/common/device/app_state.rb b/lib/appium_lib_core/common/device/app_state.rb index 1e3af414..250874d1 100644 --- a/lib/appium_lib_core/common/device/app_state.rb +++ b/lib/appium_lib_core/common/device/app_state.rb @@ -26,8 +26,8 @@ module AppState ].freeze def app_state(app_id) - # required: [['appId'], ['bundleId']] - response = execute :app_state, {}, appId: app_id + # appId is for android, bundleId is for ios. + execute_script 'mobile:queryAppState', { 'appId': app_id, 'bundleId': app_id } case response when 0, 1, 2, 3, 4 From 820973f291c6e9028c07149c5706a29fc0964385 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 10:42:50 -0700 Subject: [PATCH 04/19] replace with mobile commands --- lib/appium_lib_core/android/device.rb | 6 ++---- lib/appium_lib_core/android/device/performance.rb | 10 +++------- lib/appium_lib_core/common/command.rb | 3 --- test/functional/android/android/device_data_test.rb | 3 +-- 4 files changed, 6 insertions(+), 16 deletions(-) diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index c1122481..43fa9c81 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -244,17 +244,15 @@ module Device # @driver.get_performance_data_types #=> ["cpuinfo", "batteryinfo", "networkinfo", "memoryinfo"] # - # @deprecated Use 'mobile: getPerformanceData' extension instead. - # @!method get_performance_data(package_name:, data_type:, data_read_timeout: 1000) + # @!method get_performance_data(package_name:, data_type:) # Get the resource usage information of the application. # https://github.com/appium/appium-base-driver/blob/be29aec2318316d12b5c3295e924a5ba8f09b0fb/lib/mjsonwp/routes.js#L303 # @param [String] package_name: Package name # @param [String] data_type: Data type get with +get_performance_data_types+ - # @param [String] data_read_timeout: Command timeout. Default is 2. # # @example # - # @driver.get_performance_data package_name: package_name, data_type: data_type, data_read_timeout: 2 + # @driver.get_performance_data package_name: package_name, data_type: data_type # # @!method start_recording_screen(remote_path: nil, user: nil, pass: nil, method: 'PUT', file_field_name: nil, form_fields: nil, headers: nil, force_restart: nil, video_size: nil, time_limit: '180', bit_rate: '4000000', bug_report: nil) diff --git a/lib/appium_lib_core/android/device/performance.rb b/lib/appium_lib_core/android/device/performance.rb index 1874b8ac..f5248ab5 100644 --- a/lib/appium_lib_core/android/device/performance.rb +++ b/lib/appium_lib_core/android/device/performance.rb @@ -20,17 +20,13 @@ module Performance def self.add_methods ::Appium::Core::Device.add_endpoint_method(:get_performance_data_types) do def get_performance_data_types - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getPerformanceDataTypes' extension instead" - execute :get_performance_data_types + execute_script 'mobile: getPerformanceDataTypes', {} end end ::Appium::Core::Device.add_endpoint_method(:get_performance_data) do - def get_performance_data(package_name:, data_type:, data_read_timeout: 1000) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getPerformanceData' extension instead" - - execute(:get_performance_data, {}, - packageName: package_name, dataType: data_type, dataReadTimeout: data_read_timeout) + def get_performance_data(package_name:, data_type:) + execute_script 'mobile: getPerformanceData', { packageName: package_name, dataType: data_type } end end end diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index 38c4c8d2..a2a51d4e 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -196,7 +196,6 @@ module Commands app_installed?: [:post, 'session/:session_id/appium/device/app_installed'], activate_app: [:post, 'session/:session_id/appium/device/activate_app'], terminate_app: [:post, 'session/:session_id/appium/device/terminate_app'], - app_state: [:post, 'session/:session_id/appium/device/app_state'], shake: [:post, 'session/:session_id/appium/device/shake'], hide_keyboard: [:post, 'session/:session_id/appium/device/hide_keyboard'], press_keycode: [:post, 'session/:session_id/appium/device/press_keycode'], @@ -229,8 +228,6 @@ module Commands toggle_wifi: [:post, 'session/:session_id/appium/device/toggle_wifi'], toggle_data: [:post, 'session/:session_id/appium/device/toggle_data'], toggle_location_services: [:post, 'session/:session_id/appium/device/toggle_location_services'], - get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'], - get_performance_data: [:post, 'session/:session_id/appium/getPerformanceData'], get_network_connection: [:get, 'session/:session_id/network_connection'], # defined also in OSS set_network_connection: [:post, 'session/:session_id/network_connection'], # defined also in OSS diff --git a/test/functional/android/android/device_data_test.rb b/test/functional/android/android/device_data_test.rb index 8629e4d3..720ef589 100644 --- a/test/functional/android/android/device_data_test.rb +++ b/test/functional/android/android/device_data_test.rb @@ -71,8 +71,7 @@ def test_performance_related assert_equal [%w(user kernel), %w(0 0)], @driver.get_performance_data(package_name: 'io.appium.android.apis', - data_type: 'cpuinfo', - data_read_timeout: 10) + data_type: 'cpuinfo') end def test_take_element_screenshot From d9032e0276b299df46236fc6c5c7a308a26244e9 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 10:45:24 -0700 Subject: [PATCH 05/19] remove keycode stuff --- lib/appium_lib_core/common/base/driver.rb | 3 --- lib/appium_lib_core/common/command.rb | 2 -- lib/appium_lib_core/common/device/keyevent.rb | 4 ++-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/appium_lib_core/common/base/driver.rb b/lib/appium_lib_core/common/base/driver.rb index f87a477c..9171ed4e 100644 --- a/lib/appium_lib_core/common/base/driver.rb +++ b/lib/appium_lib_core/common/base/driver.rb @@ -542,7 +542,6 @@ def pull_folder(path) @bridge.pull_folder(path) end - # @deprecated Use 'mobile: pressKey' extension instead. # Press keycode on the device. # http://developer.android.com/reference/android/view/KeyEvent.html # @param [Integer] key The key to press. The values which have +KEYCODE_+ prefix in http://developer.android.com/reference/android/view/KeyEvent.html @@ -562,11 +561,9 @@ def pull_folder(path) # @driver.press_keycode 66, metastate: [1], flags: [32] # def press_keycode(key, metastate: [], flags: []) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: pressKey' extension instead" @bridge.press_keycode(key, metastate: metastate, flags: flags) end - # @deprecated Use 'mobile: pressKey' extension instead. # Long press keycode on the device. # http://developer.android.com/reference/android/view/KeyEvent.html # @param [Integer] key The key to long press. The values which have +KEYCODE_+ prefix in http://developer.android.com/reference/android/view/KeyEvent.html diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index a2a51d4e..e01d6f95 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -198,8 +198,6 @@ module Commands terminate_app: [:post, 'session/:session_id/appium/device/terminate_app'], shake: [:post, 'session/:session_id/appium/device/shake'], hide_keyboard: [:post, 'session/:session_id/appium/device/hide_keyboard'], - press_keycode: [:post, 'session/:session_id/appium/device/press_keycode'], - long_press_keycode: [:post, 'session/:session_id/appium/device/long_press_keycode'], push_file: [:post, 'session/:session_id/appium/device/push_file'], pull_file: [:post, 'session/:session_id/appium/device/pull_file'], pull_folder: [:post, 'session/:session_id/appium/device/pull_folder'], diff --git a/lib/appium_lib_core/common/device/keyevent.rb b/lib/appium_lib_core/common/device/keyevent.rb index 5f8b1bbf..223d1251 100644 --- a/lib/appium_lib_core/common/device/keyevent.rb +++ b/lib/appium_lib_core/common/device/keyevent.rb @@ -32,7 +32,7 @@ def press_keycode(key, metastate: [], flags: []) args[:metastate] = metastate.reduce(0) { |acc, meta| acc | meta } unless metastate.empty? args[:flags] = flags.reduce(0) { |acc, flag| acc | flag } unless flags.empty? - execute :press_keycode, {}, args + execute_script 'mobile:pressKeyCode', args end def long_press_keycode(key, metastate: [], flags: []) @@ -43,7 +43,7 @@ def long_press_keycode(key, metastate: [], flags: []) args[:metastate] = metastate.reduce(0) { |acc, meta| acc | meta } unless metastate.empty? args[:flags] = flags.reduce(0) { |acc, flag| acc | flag } unless flags.empty? - execute :long_press_keycode, {}, args + execute_script 'mobile:longPressKeyCode', args end end # module KeyEvent end # module Device From d6a3154c4e1e29b8fd6398563e4cf04a25d0050c Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 10:52:23 -0700 Subject: [PATCH 06/19] drop android emulators commands --- .../android/device/auth_finger_print.rb | 5 +---- lib/appium_lib_core/android/device/emulator.rb | 15 +++++++-------- lib/appium_lib_core/common/command.rb | 10 ---------- 3 files changed, 8 insertions(+), 22 deletions(-) diff --git a/lib/appium_lib_core/android/device/auth_finger_print.rb b/lib/appium_lib_core/android/device/auth_finger_print.rb index 31d2aa1e..1f94065c 100644 --- a/lib/appium_lib_core/android/device/auth_finger_print.rb +++ b/lib/appium_lib_core/android/device/auth_finger_print.rb @@ -20,14 +20,11 @@ module Authentication def self.add_methods ::Appium::Core::Device.add_endpoint_method(:finger_print) do def finger_print(finger_id) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: fingerprint' extension instead" - unless (1..10).cover? finger_id.to_i raise ::Appium::Core::Error::ArgumentError, "finger_id should be integer between 1 to 10. Not #{finger_id}" end - - execute(:finger_print, {}, { fingerprintId: finger_id.to_i }) + execute_script 'mobile:fingerprint', { fingerprintId: finger_id.to_i } end end end # def self.emulator_commands diff --git a/lib/appium_lib_core/android/device/emulator.rb b/lib/appium_lib_core/android/device/emulator.rb index 12efeb8d..be9caa9d 100644 --- a/lib/appium_lib_core/android/device/emulator.rb +++ b/lib/appium_lib_core/android/device/emulator.rb @@ -115,7 +115,7 @@ module Emulator def self.add_methods ::Appium::Core::Device.add_endpoint_method(:send_sms) do def send_sms(phone_number:, message:) - execute(:send_sms, {}, { phoneNumber: phone_number, message: message }) + execute_script 'mobile:sendSms', { phoneNumber: phone_number, message: message } end end @@ -125,7 +125,7 @@ def gsm_call(phone_number:, action:) raise ::Appium::Core::Error::ArgumentError, "action: should be member of #{GSM_CALL_ACTIONS}. Not #{action}." end - execute(:gsm_call, {}, { phoneNumber: phone_number, action: action }) + execute_script 'mobile:gsmCall', { phoneNumber: phone_number, action: action } end end @@ -136,8 +136,7 @@ def gsm_signal(signal_strength) "#{signal_strength} should be member of #{GSM_SIGNALS.keys} " end - execute(:gsm_signal, {}, { signalStrength: GSM_SIGNALS[signal_strength], - signalStrengh: GSM_SIGNALS[signal_strength] }) + execute 'mobile:gsmSignal', {}, { strength: GSM_SIGNALS[signal_strength] } end end @@ -147,7 +146,7 @@ def gsm_voice(state) raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{GSM_VOICE_STATES}. Not #{state}." end - execute(:gsm_voice, {}, { state: state }) + execute 'mobile:gsmVoic', {}, { state: state } end end @@ -158,7 +157,7 @@ def set_network_speed(netspeed) "The netspeed should be member of #{NET_SPEED}. Not #{netspeed}." end - execute(:set_network_speed, {}, { netspeed: netspeed }) + execute_script 'mobile:networkSpee', { speed: netspeed } end end @@ -168,7 +167,7 @@ def set_power_capacity(percent) ::Appium::Logger.warn "The percent should be between 0 and 100. Not #{percent}." end - execute(:set_power_capacity, {}, { percent: percent }) + execute_script 'mobile:powerCapacity', { percent: percent } end end @@ -178,7 +177,7 @@ def set_power_ac(state) raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{POWER_AC_STATE}. Not #{state}." end - execute(:set_power_ac, {}, { state: state }) + execute 'mobile:powerAc', { state: state } end end end # def self.emulator_commands diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index e01d6f95..a67419c1 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -203,7 +203,6 @@ module Commands pull_folder: [:post, 'session/:session_id/appium/device/pull_folder'], get_clipboard: [:post, 'session/:session_id/appium/device/get_clipboard'], set_clipboard: [:post, 'session/:session_id/appium/device/set_clipboard'], - finger_print: [:post, 'session/:session_id/appium/device/finger_print'], get_settings: [:get, 'session/:session_id/appium/settings'], update_settings: [:post, 'session/:session_id/appium/settings'], stop_recording_screen: [:post, 'session/:session_id/appium/stop_recording_screen'], @@ -229,15 +228,6 @@ module Commands get_network_connection: [:get, 'session/:session_id/network_connection'], # defined also in OSS set_network_connection: [:post, 'session/:session_id/network_connection'], # defined also in OSS - # only emulator - send_sms: [:post, 'session/:session_id/appium/device/send_sms'], - gsm_call: [:post, 'session/:session_id/appium/device/gsm_call'], - gsm_signal: [:post, 'session/:session_id/appium/device/gsm_signal'], - gsm_voice: [:post, 'session/:session_id/appium/device/gsm_voice'], - set_network_speed: [:post, 'session/:session_id/appium/device/network_speed'], - set_power_capacity: [:post, 'session/:session_id/appium/device/power_capacity'], - set_power_ac: [:post, 'session/:session_id/appium/device/power_ac'], - # For chromium: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc chrome_send_command: [:post, 'session/:session_id/goog/cdp/execute'] }.freeze From a4b58425389b5c256f9e480fa223b245d73f9f90 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 12:02:14 -0700 Subject: [PATCH 07/19] update tests --- lib/appium_lib_core/android/device.rb | 170 +----------------- .../android/device/emulator.rb | 6 +- lib/appium_lib_core/android/device/network.rb | 71 -------- .../android/device/performance.rb | 4 +- lib/appium_lib_core/common/base/bridge.rb | 14 -- lib/appium_lib_core/common/base/driver.rb | 2 - .../common/base/has_network_connection.rb | 56 ------ lib/appium_lib_core/common/command.rb | 10 -- .../common/device/app_state.rb | 2 +- .../android/webdriver/device_test.rb | 8 - .../android/device/w3c/app_management_test.rb | 8 +- test/unit/android/device/w3c/commands_test.rb | 165 +++++------------ .../android/device/w3c/definition_test.rb | 6 - test/unit/android/device/w3c/keyboard_test.rb | 24 +-- .../android/webdriver/w3c/commands_test.rb | 6 +- 15 files changed, 79 insertions(+), 473 deletions(-) delete mode 100644 lib/appium_lib_core/android/device/network.rb delete mode 100644 lib/appium_lib_core/common/base/has_network_connection.rb diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index 43fa9c81..f70c0841 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -14,7 +14,6 @@ require_relative 'device/emulator' require_relative 'device/clipboard' -require_relative 'device/network' require_relative 'device/performance' require_relative 'device/screen' require_relative 'device/auth_finger_print' @@ -77,54 +76,6 @@ module Device # @driver.get_display_density # 320 # - # @deprecated Use 'mobile: getConnectivity' extension instead. - # @!method get_network_connection - # Get the device network connection current status - # See set_network_connection method for return value - # Same as #network_connection_type in selenium-webdriver. - # - # Returns a key of {:airplane_mode: 1, wifi: 2, data: 4, all: 6, none: 0} in #network_connection_type - # Returns a number of the mode in +#get_network_connection+ - # - # @example - # - # @driver.network_connection_type #=> :all - # @driver.get_network_connection #=> 6 - # - - # @deprecated Use 'mobile: getConnectivity' extension instead. - # @!method toggle_wifi - # Switch the state of the wifi service only for Android - # - # @return [String] - # - # @example - # - # @driver.toggle_wifi - # - - # @deprecated Use 'mobile: getConnectivity' extension instead. - # @!method toggle_data - # Switch the state of data service only for Android, and the device should be rooted - # - # @return [String] - # - # @example - # - # @driver.toggle_data - # - - # @deprecated Use 'mobile: getConnectivity' extension instead. - # @!method location - # Get the location of the device. - # - # @return [::Appium::Location] - # - # @example - # - # driver.location #=> ::Appium::Location.new(10, 10, 10) - # - # @!method location= # Set the [::Appium::Location] of the device. # @@ -149,7 +100,6 @@ module Device # driver.set_location 10, 10, 0 # - # @deprecated Use 'mobile: toggleGps' extension instead. # @!method toggle_location_services # Switch the state of the location service # @@ -160,15 +110,6 @@ module Device # @driver.toggle_location_services # - # @deprecated Use 'mobile: getConnectivity' extension instead. - # @!method toggle_airplane_mode - # Toggle flight mode on or off - # - # @example - # - # @driver.toggle_airplane_mode - # - # @deprecated Use 'mobile: hideKeyboard' extension instead. # @!method hide_keyboard(close_key = nil, strategy = nil) # Hide the onscreen keyboard @@ -185,54 +126,6 @@ module Device # @driver.hide_keyboard(nil, :tapOutside) # Close a keyboard with tapping out side of keyboard # - # @deprecated Use 'mobile: startActivity' extension instead. - # @!method start_activity(opts) - # Android only. Start a new activity within the current app or launch a new app and start the target activity. - # - # Read https://developer.android.com/studio/command-line/adb#IntentSpec for each flags. - # - # @param opts [Hash] Options - # @option opts [String] :app_package The package owning the activity [required] - # @option opts [String] :app_activity The target activity [required] - # @option opts [String] :app_wait_package The package to start before the target package [optional] - # @option opts [String] :app_wait_activity The activity to start before the target activity [optional] - # @option opts [String] :intent_action The intent action to give it when start the target activity (+-a+) [optional] - # @option opts [String] :intent_category The intent category to give it when start the target activity (+-c+) [optional] - # @option opts [String] :intent_flags The intent flag to give it when start the target activity (+-f+) [optional] - # @option opts [String] :optional_intent_arguments The optional intent action to give it when start the target activity [optional] - # You can set arbitrary arguments with space as string. - # e.g. +'--ez your_extra_bool bool --ei your_extra_int 1'+ - # @option opts [bool] :dont_stop_app_on_reset Do not stop the app when the reset is called in Appium create/delete session [optional] - # - # @example - # - # start_activity app_package: 'io.appium.android.apis', - # app_activity: '.accessibility.AccessibilityNodeProviderActivity' - # - - # @deprecated Use 'mobile: setConnectivity' extension instead. - # @!method set_network_connection(mode) - # Set the device network connection mode - # Same as +#network_connection_type+ in selenium-webdriver. - # - # @param [String] mode Bit mask that represent the network mode - # Or the key matched with {:airplane_mode: 1, wifi: 2, data: 4, all: 6, none: 0} - # - # Value (Alias) | Data | Wifi | Airplane Mode - # ------------------------------------------------- - # 1 (Airplane Mode) | 0 | 0 | 1 - # 6 (All network on) | 1 | 1 | 0 - # 4 (Data only) | 1 | 0 | 0 - # 2 (Wifi only) | 0 | 1 | 0 - # 0 (None) | 0 | 0 | 0 - # - # @example - # - # @driver.set_network_connection 1 - # @driver.set_network_connection :airplane_mode - # @driver.network_connection_type = :airplane_mode # As selenium-webdriver - # - # @deprecated Use 'mobile: getPerformanceDataTypes' extension instead. # @!method get_performance_data_types # Get the information type of the system state which is supported to read such as @@ -362,87 +255,37 @@ def extended(_mod) ::Appium::Core::Device.add_endpoint_method(:open_notifications) do def open_notifications - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: openNotifications' extension instead" - - execute :open_notifications + execute_script 'mobile:openNotifications', {} end end ::Appium::Core::Device.add_endpoint_method(:current_activity) do def current_activity - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getCurrentActivity' extension instead" - - execute :current_activity + execute_script 'mobile:getCurrentActivity', {} end end ::Appium::Core::Device.add_endpoint_method(:current_package) do def current_package - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getCurrentPackage' extension instead" - - execute :current_package + execute_script 'mobile:getCurrentPackage', {} end end ::Appium::Core::Device.add_endpoint_method(:get_system_bars) do def get_system_bars - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getSystemBars' extension instead" - - execute :get_system_bars + execute_script 'mobile:getSystemBars', {} end end # as alias to get_system_bars ::Appium::Core::Device.add_endpoint_method(:system_bars) do def system_bars - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getSystemBars' extension instead" - - execute :get_system_bars + execute_script 'mobile:getSystemBars', {} end end ::Appium::Core::Device.add_endpoint_method(:toggle_location_services) do def toggle_location_services - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: toggleGps' extension instead" - - execute :toggle_location_services - end - end - - ::Appium::Core::Device.add_endpoint_method(:start_activity) do - def start_activity(opts) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: startActivity' extension instead" - - raise ::Appium::Core::Error::ArgumentError, 'opts must be a hash' unless opts.is_a? Hash - - option = {} - - app_package = opts[:app_package] - raise ::Appium::Core::Error::ArgumentError, 'app_package is required' unless app_package - - app_activity = opts[:app_activity] - raise ::Appium::Core::Error::ArgumentError, 'app_activity is required' unless app_activity - - option[:appPackage] = app_package - option[:appActivity] = app_activity - - app_wait_package = opts.fetch(:app_wait_package, nil) - app_wait_activity = opts.fetch(:app_wait_activity, nil) - option[:appWaitPackage] = app_wait_package if app_wait_package - option[:appWaitActivity] = app_wait_activity if app_wait_activity - - intent_action = opts.fetch(:intent_action, nil) - intent_category = opts.fetch(:intent_category, nil) - intent_flags = opts.fetch(:intent_flags, nil) - optional_intent_arguments = opts.fetch(:optional_intent_arguments, nil) - dont_stop_app_on_reset = opts.fetch(:dont_stop_app_on_reset, nil) - - option[:intentAction] = intent_action if intent_action - option[:intentCategory] = intent_category if intent_category - option[:intentFlags] = intent_flags if intent_flags - option[:optionalIntentArguments] = optional_intent_arguments if optional_intent_arguments - option[:dontStopAppOnReset] = dont_stop_app_on_reset if dont_stop_app_on_reset - - execute :start_activity, {}, option + execute_script 'mobile:toggleGps', {} end end @@ -480,7 +323,6 @@ def execute_cdp(cmd, **params) Screen.add_methods Performance.add_methods - Network.add_methods Clipboard.add_methods Emulator.add_methods Authentication.add_methods diff --git a/lib/appium_lib_core/android/device/emulator.rb b/lib/appium_lib_core/android/device/emulator.rb index be9caa9d..3c441dda 100644 --- a/lib/appium_lib_core/android/device/emulator.rb +++ b/lib/appium_lib_core/android/device/emulator.rb @@ -136,7 +136,7 @@ def gsm_signal(signal_strength) "#{signal_strength} should be member of #{GSM_SIGNALS.keys} " end - execute 'mobile:gsmSignal', {}, { strength: GSM_SIGNALS[signal_strength] } + execute_script 'mobile:gsmSignal', { strength: GSM_SIGNALS[signal_strength] } end end @@ -146,7 +146,7 @@ def gsm_voice(state) raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{GSM_VOICE_STATES}. Not #{state}." end - execute 'mobile:gsmVoic', {}, { state: state } + execute_script 'mobile:gsmVoic', { state: state } end end @@ -177,7 +177,7 @@ def set_power_ac(state) raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{POWER_AC_STATE}. Not #{state}." end - execute 'mobile:powerAc', { state: state } + execute_script 'mobile:powerAc', { state: state } end end end # def self.emulator_commands diff --git a/lib/appium_lib_core/android/device/network.rb b/lib/appium_lib_core/android/device/network.rb deleted file mode 100644 index 1a9fae01..00000000 --- a/lib/appium_lib_core/android/device/network.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -# 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. - -module Appium - module Core - module Android - module Device - module Network - def self.add_methods - ::Appium::Core::Device.add_endpoint_method(:get_network_connection) do - def get_network_connection - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getConnectivity' extension instead" - - execute :get_network_connection - end - end - - ::Appium::Core::Device.add_endpoint_method(:toggle_wifi) do - def toggle_wifi - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: setConnectivity' extension instead" - - execute :toggle_wifi - end - end - - ::Appium::Core::Device.add_endpoint_method(:toggle_data) do - def toggle_data - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: setConnectivity' extension instead" - - execute :toggle_data - end - end - - ::Appium::Core::Device.add_endpoint_method(:set_network_connection) do - def set_network_connection(mode) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: setConnectivity' extension instead" - - # same as ::Selenium::WebDriver::DriverExtensions::HasNetworkConnection - # But this method accept number - connection_type = { airplane_mode: 1, wifi: 2, data: 4, all: 6, none: 0 } - type = connection_type.key?(mode) ? connection_type[mode] : mode.to_i - - execute :set_network_connection, {}, type: type - end - end - - ::Appium::Core::Device.add_endpoint_method(:toggle_airplane_mode) do - def toggle_airplane_mode - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: setConnectivity' extension instead" - - execute :toggle_airplane_mode - end - alias_method :toggle_flight_mode, :toggle_airplane_mode - end - end - end # module Network - end # module Device - end # module Android - end # module Core -end # module Appium diff --git a/lib/appium_lib_core/android/device/performance.rb b/lib/appium_lib_core/android/device/performance.rb index f5248ab5..66ea98e0 100644 --- a/lib/appium_lib_core/android/device/performance.rb +++ b/lib/appium_lib_core/android/device/performance.rb @@ -20,13 +20,13 @@ module Performance def self.add_methods ::Appium::Core::Device.add_endpoint_method(:get_performance_data_types) do def get_performance_data_types - execute_script 'mobile: getPerformanceDataTypes', {} + execute_script 'mobile:getPerformanceDataTypes', {} end end ::Appium::Core::Device.add_endpoint_method(:get_performance_data) do def get_performance_data(package_name:, data_type:) - execute_script 'mobile: getPerformanceData', { packageName: package_name, dataType: data_type } + execute_script 'mobile:getPerformanceData', { packageName: package_name, dataType: data_type } end end end diff --git a/lib/appium_lib_core/common/base/bridge.rb b/lib/appium_lib_core/common/base/bridge.rb index e947f4c5..18c04d1d 100644 --- a/lib/appium_lib_core/common/base/bridge.rb +++ b/lib/appium_lib_core/common/base/bridge.rb @@ -245,20 +245,6 @@ def convert_to_element(id) ::Appium::Core::Element.new self, element_id_from(id) end - # For Appium - # override - # called in 'extend DriverExtensions::HasNetworkConnection' - def network_connection - execute :get_network_connection - end - - # For Appium - # override - # called in 'extend DriverExtensions::HasNetworkConnection' - def network_connection=(type) - execute :set_network_connection, {}, { parameters: { type: type } } - end - # For Appium # No implementation for W3C webdriver module # called in 'extend DriverExtensions::HasLocation' diff --git a/lib/appium_lib_core/common/base/driver.rb b/lib/appium_lib_core/common/base/driver.rb index 9171ed4e..94d129c2 100644 --- a/lib/appium_lib_core/common/base/driver.rb +++ b/lib/appium_lib_core/common/base/driver.rb @@ -20,7 +20,6 @@ require_relative 'rotable' require_relative 'remote_status' require_relative 'has_location' -require_relative 'has_network_connection' require_relative '../wait' module Appium @@ -35,7 +34,6 @@ class Driver < ::Selenium::WebDriver::Driver include ::Appium::Core::Base::TakesScreenshot include ::Appium::Core::Base::HasRemoteStatus include ::Appium::Core::Base::HasLocation - include ::Appium::Core::Base::HasNetworkConnection include ::Appium::Core::Waitable diff --git a/lib/appium_lib_core/common/base/has_network_connection.rb b/lib/appium_lib_core/common/base/has_network_connection.rb deleted file mode 100644 index 119aa2d5..00000000 --- a/lib/appium_lib_core/common/base/has_network_connection.rb +++ /dev/null @@ -1,56 +0,0 @@ -# frozen_string_literal: true - -# 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. - -module Appium - module Core - class Base - # - # @api private - # - module HasNetworkConnection - def network_connection_type - connection_value = @bridge.network_connection - - connection_type = values_to_type[connection_value] - - # In case the connection type is not recognized return the - # connection value. - connection_type || connection_value - end - - def network_connection_type=(connection_type) - raise ::Appium::Core::Error::ArgumentError, 'Invalid connection type' unless valid_type? connection_type - - connection_value = type_to_values[connection_type] - - @bridge.network_connection = connection_value - end - - private - - def type_to_values - { airplane_mode: 1, wifi: 2, data: 4, all: 6, none: 0 } - end - - def values_to_type - type_to_values.invert - end - - def valid_type?(type) - type_to_values.keys.include? type - end - end - end - end -end diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index a67419c1..839f8b06 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -215,18 +215,8 @@ module Commands }.freeze COMMAND_ANDROID = { - open_notifications: [:post, 'session/:session_id/appium/device/open_notifications'], - toggle_airplane_mode: [:post, 'session/:session_id/appium/device/toggle_airplane_mode'], - start_activity: [:post, 'session/:session_id/appium/device/start_activity'], - current_activity: [:get, 'session/:session_id/appium/device/current_activity'], - current_package: [:get, 'session/:session_id/appium/device/current_package'], - get_system_bars: [:get, 'session/:session_id/appium/device/system_bars'], get_display_density: [:get, 'session/:session_id/appium/device/display_density'], - toggle_wifi: [:post, 'session/:session_id/appium/device/toggle_wifi'], - toggle_data: [:post, 'session/:session_id/appium/device/toggle_data'], toggle_location_services: [:post, 'session/:session_id/appium/device/toggle_location_services'], - get_network_connection: [:get, 'session/:session_id/network_connection'], # defined also in OSS - set_network_connection: [:post, 'session/:session_id/network_connection'], # defined also in OSS # For chromium: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc chrome_send_command: [:post, 'session/:session_id/goog/cdp/execute'] diff --git a/lib/appium_lib_core/common/device/app_state.rb b/lib/appium_lib_core/common/device/app_state.rb index 250874d1..53d23713 100644 --- a/lib/appium_lib_core/common/device/app_state.rb +++ b/lib/appium_lib_core/common/device/app_state.rb @@ -27,7 +27,7 @@ module AppState def app_state(app_id) # appId is for android, bundleId is for ios. - execute_script 'mobile:queryAppState', { 'appId': app_id, 'bundleId': app_id } + response = execute_script 'mobile:queryAppState', { 'appId': app_id, 'bundleId': app_id } case response when 0, 1, 2, 3, 4 diff --git a/test/functional/android/webdriver/device_test.rb b/test/functional/android/webdriver/device_test.rb index 0f2c7848..d51e16a6 100644 --- a/test/functional/android/webdriver/device_test.rb +++ b/test/functional/android/webdriver/device_test.rb @@ -126,14 +126,6 @@ def test_logs assert_equal %i(logcat bugreport server), @driver.logs.available_types assert @driver.logs.get(:logcat) end - - def test_network_connection - assert @driver.get_network_connection - assert @driver.network_connection_type - assert @driver.set_network_connection(6) - # TODO: depends on selenium-webdriver. Test failed with webdriver 3.11.0 with a number. - assert @driver.network_connection_type = :all - end end end end diff --git a/test/unit/android/device/w3c/app_management_test.rb b/test/unit/android/device/w3c/app_management_test.rb index 38361da0..761eedcc 100644 --- a/test/unit/android/device/w3c/app_management_test.rb +++ b/test/unit/android/device/w3c/app_management_test.rb @@ -76,12 +76,16 @@ def test_activate_app end def test_app_state - stub_request(:post, "#{SESSION}/appium/device/app_state") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { + script: 'mobile:queryAppState', + args: [{ 'appId' => 'com.app.id', 'bundleId' => 'com.app.id' }] + }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 4 }.to_json) state = @driver.app_state 'com.app.id' - assert_requested(:post, "#{SESSION}/appium/device/app_state", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) assert_equal :running_in_foreground, state end diff --git a/test/unit/android/device/w3c/commands_test.rb b/test/unit/android/device/w3c/commands_test.rb index 327da143..2385073c 100644 --- a/test/unit/android/device/w3c/commands_test.rb +++ b/test/unit/android/device/w3c/commands_test.rb @@ -67,43 +67,38 @@ def test_device_time_with_format end def test_open_notifications - stub_request(:post, "#{SESSION}/appium/device/open_notifications") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:openNotifications', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) @driver.open_notifications - assert_requested(:post, "#{SESSION}/appium/device/open_notifications", times: 1) - end - - def test_toggle_airplane_mode - stub_request(:post, "#{SESSION}/appium/device/toggle_airplane_mode") - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - - @driver.toggle_airplane_mode - - assert_requested(:post, "#{SESSION}/appium/device/toggle_airplane_mode", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_current_activity - stub_request(:get, "#{SESSION}/appium/device/current_activity") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getCurrentActivity', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 'A' }.to_json) @driver.current_activity - assert_requested(:get, "#{SESSION}/appium/device/current_activity", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_current_package - stub_request(:get, "#{SESSION}/appium/device/current_package") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getCurrentPackage', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 'A' }.to_json) @driver.current_package - assert_requested(:get, "#{SESSION}/appium/device/current_package", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_get_system_bars - stub_request(:get, "#{SESSION}/appium/device/system_bars") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getSystemBars', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: { statusBar: { visible: true, x: 0, y: 0, width: 1080, height: 63 }, navigationBar: { visible: true, x: 0, y: 1794, width: 1080, height: 126 } @@ -111,7 +106,7 @@ def test_get_system_bars info = @driver.get_system_bars - assert_requested(:get, "#{SESSION}/appium/device/system_bars", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) assert_equal({ 'visible' => true, 'x' => 0, 'y' => 0, 'width' => 1080, 'height' => 63 }, info['statusBar']) end @@ -124,22 +119,14 @@ def test_get_display_density assert_requested(:get, "#{SESSION}/appium/device/display_density", times: 1) end - def test_get_network_connection - stub_request(:get, "#{SESSION}/network_connection") - .to_return(headers: HEADER, status: 200, body: { value: 'A' }.to_json) - - @driver.get_network_connection - - assert_requested(:get, "#{SESSION}/network_connection", times: 1) - end - def test_get_performance_data_types - stub_request(:post, "#{SESSION}/appium/performanceData/types") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getPerformanceDataTypes', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: ['a'] }.to_json) @driver.get_performance_data_types - assert_requested(:post, "#{SESSION}/appium/performanceData/types", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_push_file @@ -214,56 +201,17 @@ def test_settings_update_equal assert_requested(:post, "#{SESSION}/appium/settings", times: 1) end - def test_start_activity - stub_request(:post, "#{SESSION}/appium/device/start_activity") - .with(body: { appPackage: 'package', appActivity: 'activity', intentAction: 'action.MAIN' }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) - @driver.start_activity(app_activity: 'activity', app_package: 'package', intent_action: 'action.MAIN') - - assert_requested(:post, "#{SESSION}/appium/device/start_activity", times: 1) - end - - def test_start_activity_with_wait - stub_request(:post, "#{SESSION}/appium/device/start_activity") - .with(body: { appPackage: 'package', appActivity: 'activity', - appWaitPackage: 'wait_package', appWaitActivity: 'wait_activity', - intentAction: 'action.MAIN', dontStopAppOnReset: true }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) - - @driver.start_activity(app_activity: 'activity', app_package: 'package', - app_wait_package: 'wait_package', app_wait_activity: 'wait_activity', - intent_action: 'action.MAIN', dont_stop_app_on_reset: true) - - assert_requested(:post, "#{SESSION}/appium/device/start_activity", times: 1) - end - - def test_set_network_connection - stub_request(:post, "#{SESSION}/network_connection") - .with(body: { type: 1 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) - - @driver.set_network_connection 1 - - assert_requested(:post, "#{SESSION}/network_connection", times: 1) - end - - def test_set_network_connection_key - stub_request(:post, "#{SESSION}/network_connection") - .with(body: { type: 6 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) - - @driver.set_network_connection :all - - assert_requested(:post, "#{SESSION}/network_connection", times: 1) - end - def test_get_perfoemance_data - stub_request(:post, "#{SESSION}/appium/getPerformanceData") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { + script: 'mobile:getPerformanceData', + args: [{ 'packageName' => 'package_name', 'dataType' => 'type' }] + }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.get_performance_data(package_name: 'package_name', data_type: 'type') - assert_requested(:post, "#{SESSION}/appium/getPerformanceData", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_start_recording_screen_default @@ -336,105 +284,84 @@ def test_stop_recording_screen_custom # emulator def test_send_sms - stub_request(:post, "#{SESSION}/appium/device/send_sms") - .with(body: { phoneNumber: '00000000000', message: 'test message' }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:sendSms', args: [{ phoneNumber: '00000000000', message: 'test message' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.send_sms phone_number: '00000000000', message: 'test message' - assert_requested(:post, "#{SESSION}/appium/device/send_sms", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_gsm_call - stub_request(:post, "#{SESSION}/appium/device/gsm_call") - .with(body: { phoneNumber: '00000000000', action: 'call' }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:gsmCall', args: [{ phoneNumber: '00000000000', action: 'call' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.gsm_call phone_number: '00000000000', action: :call - assert_requested(:post, "#{SESSION}/appium/device/gsm_call", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_gsm_signal - stub_request(:post, "#{SESSION}/appium/device/gsm_signal") - .with(body: { signalStrength: ::Appium::Core::Android::Device::Emulator::GSM_SIGNALS[:good], - signalStrengh: ::Appium::Core::Android::Device::Emulator::GSM_SIGNALS[:good] }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:gsmSignal', +args: [{ strength: ::Appium::Core::Android::Device::Emulator::GSM_SIGNALS[:good] }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.gsm_signal :good - assert_requested(:post, "#{SESSION}/appium/device/gsm_signal", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_gsm_voice - stub_request(:post, "#{SESSION}/appium/device/gsm_voice") - .with(body: { state: 'on' }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:gsmVoic', args: [{ state: 'on' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.gsm_voice :on - assert_requested(:post, "#{SESSION}/appium/device/gsm_voice", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_network_speed - stub_request(:post, "#{SESSION}/appium/device/network_speed") - .with(body: { netspeed: 'gsm' }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:networkSpee', args: [{ speed: 'gsm' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.set_network_speed :gsm - assert_requested(:post, "#{SESSION}/appium/device/network_speed", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_set_power_capacity - stub_request(:post, "#{SESSION}/appium/device/power_capacity") - .with(body: { percent: 10 }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:powerCapacity', args: [{ percent: 10 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.set_power_capacity 10 - assert_requested(:post, "#{SESSION}/appium/device/power_capacity", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_power_ac - stub_request(:post, "#{SESSION}/appium/device/power_ac") - .with(body: { state: 'on' }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:powerAc', args: [{ state: 'on' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.set_power_ac :on - assert_requested(:post, "#{SESSION}/appium/device/power_ac", times: 1) - end - - # toggles - def test_toggle_wifi - stub_request(:post, "#{SESSION}/appium/device/toggle_wifi") - .with(body: '{}') - .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) - - @driver.toggle_wifi - - assert_requested(:post, "#{SESSION}/appium/device/toggle_wifi", times: 1) - end - - def test_toggle_data - stub_request(:post, "#{SESSION}/appium/device/toggle_data") - .with(body: '{}') - .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) - - @driver.toggle_data - - assert_requested(:post, "#{SESSION}/appium/device/toggle_data", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_toggle_location_services - stub_request(:post, "#{SESSION}/appium/device/toggle_location_services") - .with(body: '{}') + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:toggleGps', args: [{}] }) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.toggle_location_services - assert_requested(:post, "#{SESSION}/appium/device/toggle_location_services", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_get_battery_info diff --git a/test/unit/android/device/w3c/definition_test.rb b/test/unit/android/device/w3c/definition_test.rb index 5d167f02..7d57ffa1 100644 --- a/test/unit/android/device/w3c/definition_test.rb +++ b/test/unit/android/device/w3c/definition_test.rb @@ -50,14 +50,11 @@ def test_with_arg_definitions :device_time, :current_context, :open_notifications, - :toggle_airplane_mode, :current_activity, :current_package, :get_system_bars, :get_display_density, :is_keyboard_shown, - :get_network_connection, - :get_performance_data_types, :available_contexts, :set_context, :app_strings, @@ -78,9 +75,6 @@ def test_with_arg_definitions :pull_folder, :get_settings, :update_settings, - :start_activity, - :set_network_connection, - :get_performance_data, :get_clipboard, :set_clipboard, :execute_driver, diff --git a/test/unit/android/device/w3c/keyboard_test.rb b/test/unit/android/device/w3c/keyboard_test.rb index 6a2483da..d211f9be 100644 --- a/test/unit/android/device/w3c/keyboard_test.rb +++ b/test/unit/android/device/w3c/keyboard_test.rb @@ -49,26 +49,26 @@ def test_hide_keyboard # keypress def test_press_keycode - stub_request(:post, "#{SESSION}/appium/device/press_keycode") - .with(body: { keycode: 86 }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:pressKeyCode', args: [{ keycode: 86 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.press_keycode 86 - assert_requested(:post, "#{SESSION}/appium/device/press_keycode", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end # keypress def test_press_keycode_with_flags - stub_request(:post, "#{SESSION}/appium/device/press_keycode") - .with(body: { keycode: 86, metastate: 2_097_153, flags: 44 }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:pressKeyCode', args: [{ keycode: 86, metastate: 2_097_153, flags: 44 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) # metastate is META_SHIFT_ON and META_NUM_LOCK_ON # flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE, FLAG_FROM_SYSTEM @driver.press_keycode 86, metastate: [0x00000001, 0x00200000], flags: [0x20, 0x00000004, 0x00000008] - assert_requested(:post, "#{SESSION}/appium/device/press_keycode", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end # keypress @@ -87,26 +87,26 @@ def test_press_keycode_with_flags_with_wrong_metastate # keypress def test_long_press_keycode - stub_request(:post, "#{SESSION}/appium/device/long_press_keycode") - .with(body: { keycode: 86 }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:longPressKeyCode', args: [{ keycode: 86 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.long_press_keycode 86 - assert_requested(:post, "#{SESSION}/appium/device/long_press_keycode", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end # keypress def test_long_press_keycodewith_flags - stub_request(:post, "#{SESSION}/appium/device/long_press_keycode") - .with(body: { keycode: 86, metastate: 1, flags: 36 }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:longPressKeyCode', args: [{ keycode: 86, metastate: 1, flags: 36 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) # metastate is META_SHIFT_ON # flags is CANCELFLAG_CANCELEDED, FLAG_KEEP_TOUCH_MODE @driver.long_press_keycode 86, metastate: [1], flags: [32, 4] - assert_requested(:post, "#{SESSION}/appium/device/long_press_keycode", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end # keypress diff --git a/test/unit/android/webdriver/w3c/commands_test.rb b/test/unit/android/webdriver/w3c/commands_test.rb index 056550e1..af6bb130 100644 --- a/test/unit/android/webdriver/w3c/commands_test.rb +++ b/test/unit/android/webdriver/w3c/commands_test.rb @@ -246,8 +246,8 @@ def test_active_element end def test_finger_print - stub_request(:post, "#{SESSION}/appium/device/finger_print") - .with(body: { fingerprintId: 1 }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:fingerprint', 'args': [{ 'fingerprintId' => 1 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: { finger: 'name' } }.to_json) error = assert_raises ::Appium::Core::Error::ArgumentError do @@ -257,7 +257,7 @@ def test_finger_print @driver.finger_print 1 - assert_requested(:post, "#{SESSION}/appium/device/finger_print", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_remote From a50c417a9a542b74e9678779082d09796170c405 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 12:38:19 -0700 Subject: [PATCH 08/19] replace more --- lib/appium_lib_core/android/device.rb | 1 - lib/appium_lib_core/android/device/screen.rb | 4 +--- lib/appium_lib_core/common/command.rb | 7 +------ lib/appium_lib_core/ios/device.rb | 4 ++-- test/unit/android/device/w3c/commands_test.rb | 5 +++-- test/unit/ios/device/w3c/commands_test.rb | 10 ++++++---- 6 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index f70c0841..d1bd8797 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -66,7 +66,6 @@ module Device # @driver.system_bars # - # @deprecated Use 'mobile: getDisplayDensity' extension instead. # @!method get_display_density # Get connected device's density. # @return [Integer] The size of density diff --git a/lib/appium_lib_core/android/device/screen.rb b/lib/appium_lib_core/android/device/screen.rb index 6e464f47..1c5c3d1c 100644 --- a/lib/appium_lib_core/android/device/screen.rb +++ b/lib/appium_lib_core/android/device/screen.rb @@ -20,9 +20,7 @@ module Screen def self.add_methods ::Appium::Core::Device.add_endpoint_method(:get_display_density) do def get_display_density - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getDisplayDensity' extension instead" - - execute :get_display_density + execute_script 'mobile:getDisplayDensity', {} end end diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index 839f8b06..ff2be24e 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -215,17 +215,12 @@ module Commands }.freeze COMMAND_ANDROID = { - get_display_density: [:get, 'session/:session_id/appium/device/display_density'], - toggle_location_services: [:post, 'session/:session_id/appium/device/toggle_location_services'], # For chromium: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc chrome_send_command: [:post, 'session/:session_id/goog/cdp/execute'] }.freeze - COMMAND_IOS = { - touch_id: [:post, 'session/:session_id/appium/simulator/touch_id'], - toggle_touch_id_enrollment: [:post, 'session/:session_id/appium/simulator/toggle_touch_id_enrollment'] - }.freeze + COMMAND_IOS = {}.freeze COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).merge(COMMAND_IOS).freeze end # module Commands diff --git a/lib/appium_lib_core/ios/device.rb b/lib/appium_lib_core/ios/device.rb index fc0aa7ff..26d1aad8 100644 --- a/lib/appium_lib_core/ios/device.rb +++ b/lib/appium_lib_core/ios/device.rb @@ -75,13 +75,13 @@ def extended(_mod) ::Appium::Core::Device.add_endpoint_method(:touch_id) do def touch_id(match = true) - execute :touch_id, {}, match: match + execute_script 'mobile:sendBiometricMatch', { 'type': 'touch_id', match: match } end end ::Appium::Core::Device.add_endpoint_method(:toggle_touch_id_enrollment) do def toggle_touch_id_enrollment(enabled = true) - execute :toggle_touch_id_enrollment, {}, enabled: enabled + execute_script 'mobile:enrollBiometric', { 'isEnabled': enabled } end end diff --git a/test/unit/android/device/w3c/commands_test.rb b/test/unit/android/device/w3c/commands_test.rb index 2385073c..f03ebe5d 100644 --- a/test/unit/android/device/w3c/commands_test.rb +++ b/test/unit/android/device/w3c/commands_test.rb @@ -111,12 +111,13 @@ def test_get_system_bars end def test_get_display_density - stub_request(:get, "#{SESSION}/appium/device/display_density") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getDisplayDensity', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 'A' }.to_json) @driver.get_display_density - assert_requested(:get, "#{SESSION}/appium/device/display_density", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_get_performance_data_types diff --git a/test/unit/ios/device/w3c/commands_test.rb b/test/unit/ios/device/w3c/commands_test.rb index 604c6a78..0e82cbec 100644 --- a/test/unit/ios/device/w3c/commands_test.rb +++ b/test/unit/ios/device/w3c/commands_test.rb @@ -29,21 +29,23 @@ def setup end def test_touch_id - stub_request(:post, "#{SESSION}/appium/simulator/touch_id") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:sendBiometricMatch', args: [{ type: 'touch_id', match: true }] }) .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) @driver.touch_id - assert_requested(:post, "#{SESSION}/appium/simulator/touch_id", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_toggle_touch_id_enrollment - stub_request(:post, "#{SESSION}/appium/simulator/toggle_touch_id_enrollment") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:enrollBiometric', args: [{ isEnabled: true }] }) .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) @driver.toggle_touch_id_enrollment(true) - assert_requested(:post, "#{SESSION}/appium/simulator/toggle_touch_id_enrollment", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_start_recording_screen From 269a0ead021da33bcffb9092e0c266db0a38135e Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 13:05:47 -0700 Subject: [PATCH 09/19] apply more --- lib/appium_lib_core/android/device.rb | 15 +++------------ lib/appium_lib_core/android/device/clipboard.rb | 4 ++-- lib/appium_lib_core/common/base/driver.rb | 10 ++-------- lib/appium_lib_core/common/command.rb | 13 +------------ .../common/device/app_management.rb | 2 +- lib/appium_lib_core/common/device/keyboard.rb | 9 ++++----- lib/appium_lib_core/ios/xcuitest/device.rb | 17 ++++------------- test/functional/ios/ios/device_test.rb | 2 +- .../android/device/w3c/app_management_test.rb | 11 ++++++----- test/unit/android/device/w3c/keyboard_test.rb | 11 ++++++----- test/unit/ios/device/w3c/commands_test.rb | 6 +++--- 11 files changed, 33 insertions(+), 67 deletions(-) diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index d1bd8797..b5293266 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -290,24 +290,15 @@ def toggle_location_services # Android, Override included method in bridge ::Appium::Core::Device.add_endpoint_method(:hide_keyboard) do - def hide_keyboard(close_key = nil, strategy = nil) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: hideKeyboard' extension instead" - - option = {} - - option[:key] = close_key if close_key - option[:strategy] = strategy if strategy - - execute :hide_keyboard, {}, option + def hide_keyboard(_close_key = nil) + execute_script 'mobile:hideKeyboard', {} end end # Android, Override included method in bridge ::Appium::Core::Device.add_endpoint_method(:background_app) do def background_app(duration = 0) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: backgroundApp' extension instead" - - execute :background_app, {}, seconds: duration + execute_script 'mobile:backgroundApp', { seconds: duration } end end diff --git a/lib/appium_lib_core/android/device/clipboard.rb b/lib/appium_lib_core/android/device/clipboard.rb index 36f217e5..3419e7e4 100644 --- a/lib/appium_lib_core/android/device/clipboard.rb +++ b/lib/appium_lib_core/android/device/clipboard.rb @@ -29,7 +29,7 @@ def get_clipboard(content_type: :plaintext) params = { contentType: content_type } - data = execute(:get_clipboard, {}, params) + data = execute_script 'mobile:getClipboard', params Base64.decode64 data end end @@ -47,7 +47,7 @@ def set_clipboard(content:, content_type: :plaintext, label: nil) } params[:label] = label unless label.nil? - execute(:set_clipboard, {}, params) + execute_script 'mobile:setClipboard', params end end end diff --git a/lib/appium_lib_core/common/base/driver.rb b/lib/appium_lib_core/common/base/driver.rb index 94d129c2..a95056e6 100644 --- a/lib/appium_lib_core/common/base/driver.rb +++ b/lib/appium_lib_core/common/base/driver.rb @@ -262,7 +262,6 @@ def unlock @bridge.unlock end - # @deprecated Use 'mobile: hideKeyboard' extension instead. # Hide the onscreen keyboard # @param [String] close_key The name of the key which closes the keyboard. # Defaults to 'Done' for iOS(except for XCUITest). @@ -276,12 +275,10 @@ def unlock # @driver.hide_keyboard('Finished') # Close a keyboard with the 'Finished' button # @driver.hide_keyboard(nil, :tapOutside) # Close a keyboard with tapping out side of keyboard # - def hide_keyboard(close_key = nil, strategy = nil) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: hideKeyboard' extension instead" - @bridge.hide_keyboard close_key, strategy + def hide_keyboard(close_key = nil) + @bridge.hide_keyboard close_key end - # @deprecated Use 'mobile: isKeyboardShown' extension instead. # Get whether keyboard is displayed or not. # @return [Boolean] Return true if keyboard is shown. Return false if keyboard is hidden. # @@ -290,7 +287,6 @@ def hide_keyboard(close_key = nil, strategy = nil) # @driver.keyboard_shown? # true # def keyboard_shown? - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: isKeyboardShown' extension instead" @bridge.is_keyboard_shown end alias is_keyboard_shown keyboard_shown? @@ -581,7 +577,6 @@ def press_keycode(key, metastate: [], flags: []) # @driver.long_press_keycode 66, metastate: [1], flags: [32, 8192] # def long_press_keycode(key, metastate: [], flags: []) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: pressKey' extension instead" @bridge.long_press_keycode(key, metastate: metastate, flags: flags) end @@ -594,7 +589,6 @@ def long_press_keycode(key, metastate: [], flags: []) # @driver.app_strings #=> "TransitionsTitle"=>"Transitions", "WebTitle"=>"Web" # def app_strings(language = nil) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getAppStrings' extension instead" @bridge.app_strings(language) end diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index ff2be24e..9de3ee9e 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -123,7 +123,6 @@ module Commands element_click: [:post, 'session/:session_id/element/:id/click'], element_tap: [:post, 'session/:session_id/element/:id/tap'], element_clear: [:post, 'session/:session_id/element/:id/clear'], - element_send_keys: [:post, 'session/:session_id/element/:id/value'], # # alerts @@ -184,9 +183,6 @@ module Commands set_context: [:post, 'session/:session_id/context'], current_context: [:get, 'session/:session_id/context'], - background_app: [:post, 'session/:session_id/appium/app/background'], - app_strings: [:post, 'session/:session_id/appium/app/strings'], - device_locked?: [:post, 'session/:session_id/appium/device/is_locked'], unlock: [:post, 'session/:session_id/appium/device/unlock'], lock: [:post, 'session/:session_id/appium/device/lock'], @@ -197,32 +193,25 @@ module Commands activate_app: [:post, 'session/:session_id/appium/device/activate_app'], terminate_app: [:post, 'session/:session_id/appium/device/terminate_app'], shake: [:post, 'session/:session_id/appium/device/shake'], - hide_keyboard: [:post, 'session/:session_id/appium/device/hide_keyboard'], push_file: [:post, 'session/:session_id/appium/device/push_file'], pull_file: [:post, 'session/:session_id/appium/device/pull_file'], pull_folder: [:post, 'session/:session_id/appium/device/pull_folder'], - get_clipboard: [:post, 'session/:session_id/appium/device/get_clipboard'], - set_clipboard: [:post, 'session/:session_id/appium/device/set_clipboard'], get_settings: [:get, 'session/:session_id/appium/settings'], update_settings: [:post, 'session/:session_id/appium/settings'], stop_recording_screen: [:post, 'session/:session_id/appium/stop_recording_screen'], start_recording_screen: [:post, 'session/:session_id/appium/start_recording_screen'], compare_images: [:post, 'session/:session_id/appium/compare_images'], - is_keyboard_shown: [:get, 'session/:session_id/appium/device/is_keyboard_shown'], execute_driver: [:post, 'session/:session_id/appium/execute_driver'], post_log_event: [:post, 'session/:session_id/appium/log_event'], get_log_events: [:post, 'session/:session_id/appium/events'] }.freeze COMMAND_ANDROID = { - # For chromium: https://chromium.googlesource.com/chromium/src/+/master/chrome/test/chromedriver/server/http_handler.cc chrome_send_command: [:post, 'session/:session_id/goog/cdp/execute'] }.freeze - COMMAND_IOS = {}.freeze - - COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).merge(COMMAND_IOS).freeze + COMMANDS = {}.merge(COMMAND).merge(COMMAND_ANDROID).freeze end # module Commands end # module Core end # module Appium diff --git a/lib/appium_lib_core/common/device/app_management.rb b/lib/appium_lib_core/common/device/app_management.rb index 2312f496..706be79c 100644 --- a/lib/appium_lib_core/common/device/app_management.rb +++ b/lib/appium_lib_core/common/device/app_management.rb @@ -19,7 +19,7 @@ module Device module AppManagement def app_strings(language = nil) opts = language ? { language: language } : {} - execute :app_strings, {}, opts + execute_script 'mobile:getAppStrings', opts end def background_app(duration = 0) diff --git a/lib/appium_lib_core/common/device/keyboard.rb b/lib/appium_lib_core/common/device/keyboard.rb index 868d914b..43ef52f8 100644 --- a/lib/appium_lib_core/common/device/keyboard.rb +++ b/lib/appium_lib_core/common/device/keyboard.rb @@ -17,17 +17,16 @@ module Core class Base module Device module Keyboard - def hide_keyboard(close_key = nil, strategy = nil) + def hide_keyboard(close_key = nil) option = {} - option[:key] = close_key || 'Done' # default to Done key. - option[:strategy] = strategy || :pressKey # default to pressKey + option[:key] = close_key || 'Done' # default to Done key. - execute :hide_keyboard, {}, option + execute_script 'mobile:hideKeyboard', option end def is_keyboard_shown # rubocop:disable Naming/PredicateName - execute :is_keyboard_shown + execute_script 'mobile:isKeyboardShown', {} end end # module Keyboard end # module Device diff --git a/lib/appium_lib_core/ios/xcuitest/device.rb b/lib/appium_lib_core/ios/xcuitest/device.rb index 6604aab2..8f7d08ea 100644 --- a/lib/appium_lib_core/ios/xcuitest/device.rb +++ b/lib/appium_lib_core/ios/xcuitest/device.rb @@ -25,13 +25,9 @@ module Device # rubocop:disable Layout/LineLength - # @deprecated Use 'mobile: hideKeyboard' extension instead. - # @!method hide_keyboard(close_key = nil, strategy = nil) + # @!method hide_keyboard(close_key = nil) # Hide the onscreen keyboard # @param [String] close_key The name of the key which closes the keyboard. - # @param [Symbol] strategy The symbol of the strategy which closes the keyboard. - # XCUITest ignore this argument. - # Default for iOS is +:pressKey+. Default for Android is +:tapOutside+. # # @example # @@ -39,7 +35,6 @@ module Device # @driver.hide_keyboard('Finished') # Close a keyboard with the 'Finished' button # - # @deprecated Use 'mobile: backgroundApp' extension instead. # @!method background_app(duration = 0) # Backgrounds the app for a set number of seconds. # This is a blocking application. @@ -183,23 +178,19 @@ class << self def extended(_mod) # Xcuitest, Override included method in bridge ::Appium::Core::Device.add_endpoint_method(:hide_keyboard) do - def hide_keyboard(close_key = nil, strategy = nil) + def hide_keyboard(close_key = nil) option = {} option[:key] = close_key if close_key - option[:strategy] = strategy if strategy - execute :hide_keyboard, {}, option + execute_script 'mobile:hideKeyboard', option end end # Xcuitest, Override included method in bridge ::Appium::Core::Device.add_endpoint_method(:background_app) do def background_app(duration = 0) - # https://github.com/appium/ruby_lib/issues/500, https://github.com/appium/appium/issues/7741 - # 'execute :background_app, {}, seconds: { timeout: duration_milli_sec }' works over Appium 1.6.4 - duration_milli_sec = duration.nil? ? nil : duration * 1000 - execute :background_app, {}, seconds: { timeout: duration_milli_sec } + execute_script 'mobile:backgroundApp', { seconds: duration } end end diff --git a/test/functional/ios/ios/device_test.rb b/test/functional/ios/ios/device_test.rb index f1255bf4..b6926ac9 100644 --- a/test/functional/ios/ios/device_test.rb +++ b/test/functional/ios/ios/device_test.rb @@ -221,7 +221,7 @@ def test_hidekeyboard @@core.wait do @@driver.hide_keyboard - sleep 1 # wait animation + sleep 2 # wait animation end m = assert_raises ::Selenium::WebDriver::Error::WebDriverError do diff --git a/test/unit/android/device/w3c/app_management_test.rb b/test/unit/android/device/w3c/app_management_test.rb index 761eedcc..659c7dd9 100644 --- a/test/unit/android/device/w3c/app_management_test.rb +++ b/test/unit/android/device/w3c/app_management_test.rb @@ -29,22 +29,23 @@ def setup end def test_app_strings - stub_request(:post, "#{SESSION}/appium/app/strings") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getAppStrings', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 'xxxx' }.to_json) @driver.app_strings - assert_requested(:post, "#{SESSION}/appium/app/strings", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_background_app - stub_request(:post, "#{SESSION}/appium/app/background") - .with(body: { seconds: 0 }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:backgroundApp', args: [{ seconds: 0 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.background_app 0 - assert_requested(:post, "#{SESSION}/appium/app/background", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_terminate_app diff --git a/test/unit/android/device/w3c/keyboard_test.rb b/test/unit/android/device/w3c/keyboard_test.rb index d211f9be..50c2ca1c 100644 --- a/test/unit/android/device/w3c/keyboard_test.rb +++ b/test/unit/android/device/w3c/keyboard_test.rb @@ -29,22 +29,23 @@ def setup end def test_is_keyboard_shown - stub_request(:get, "#{SESSION}/appium/device/is_keyboard_shown") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:isKeyboardShown', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 'A' }.to_json) @driver.is_keyboard_shown - assert_requested(:get, "#{SESSION}/appium/device/is_keyboard_shown", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_hide_keyboard - stub_request(:post, "#{SESSION}/appium/device/hide_keyboard") - .with(body: { key: 'Done' }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:hideKeyboard', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.hide_keyboard 'Done' - assert_requested(:post, "#{SESSION}/appium/device/hide_keyboard", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end # keypress diff --git a/test/unit/ios/device/w3c/commands_test.rb b/test/unit/ios/device/w3c/commands_test.rb index 0e82cbec..a0dda5c9 100644 --- a/test/unit/ios/device/w3c/commands_test.rb +++ b/test/unit/ios/device/w3c/commands_test.rb @@ -135,13 +135,13 @@ def test_method_missing end def test_background_app - stub_request(:post, "#{SESSION}/appium/app/background") - .with(body: { seconds: { timeout: 0 } }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:backgroundApp', args: [{ seconds: 0 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.background_app 0 - assert_requested(:post, "#{SESSION}/appium/app/background", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end end # class CommandsTest end # module W3C From 450a821c3d2e8903b1d180d6a62b316aef6ba4e0 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 13:10:17 -0700 Subject: [PATCH 10/19] device time --- lib/appium_lib_core/android/device.rb | 7 ------- lib/appium_lib_core/common/base/driver.rb | 4 ---- lib/appium_lib_core/common/device/device.rb | 3 ++- test/unit/android/device/w3c/commands_test.rb | 12 ++++++------ 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index b5293266..a6b87575 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -26,7 +26,6 @@ module Device # rubocop:disable Layout/LineLength - # @deprecated Use 'mobile: openNotifications' extension instead. # @!method open_notifications # Open Android notifications # @@ -35,7 +34,6 @@ module Device # @driver.open_notifications # - # @deprecated Use 'mobile: getCurrentActivity' extension instead. # @!method current_activity # Get current activity name # @return [String] An activity name @@ -45,7 +43,6 @@ module Device # @driver.current_activity # '.ApiDemos' # - # @deprecated Use 'mobile: getCurrentPackage' extension instead. # @!method current_package # Get current package name # @return [String] A package name @@ -55,7 +52,6 @@ module Device # @driver.current_package # 'com.example.android.apis' # - # @deprecated Use 'mobile: getSystemBars' extension instead. # @!method get_system_bars # Get system bar's information # @return [String] @@ -109,7 +105,6 @@ module Device # @driver.toggle_location_services # - # @deprecated Use 'mobile: hideKeyboard' extension instead. # @!method hide_keyboard(close_key = nil, strategy = nil) # Hide the onscreen keyboard # @param [String] close_key The name of the key which closes the keyboard. @@ -125,7 +120,6 @@ module Device # @driver.hide_keyboard(nil, :tapOutside) # Close a keyboard with tapping out side of keyboard # - # @deprecated Use 'mobile: getPerformanceDataTypes' extension instead. # @!method get_performance_data_types # Get the information type of the system state which is supported to read such as # cpu, memory, network, battery via adb commands. @@ -214,7 +208,6 @@ module Device # @driver.set_clipboard(content: 'happy testing') #=> {"protocol"=>"W3C"} # - # @deprecated Use 'mobile: fingerprint' extension instead. # @!method finger_print(finger_id) # Authenticate users by using their finger print scans on supported emulators. # diff --git a/lib/appium_lib_core/common/base/driver.rb b/lib/appium_lib_core/common/base/driver.rb index a95056e6..c2f9ac6d 100644 --- a/lib/appium_lib_core/common/base/driver.rb +++ b/lib/appium_lib_core/common/base/driver.rb @@ -580,7 +580,6 @@ def long_press_keycode(key, metastate: [], flags: []) @bridge.long_press_keycode(key, metastate: metastate, flags: flags) end - # @deprecated Use 'mobile: getAppStrings' extension instead. # Return the hash of all localization strings. # @return [Hash] # @@ -592,7 +591,6 @@ def app_strings(language = nil) @bridge.app_strings(language) end - # @deprecated Use 'mobile: backgroundApp' extension instead. # Backgrounds the app for a set number of seconds. # This is a blocking application # @param [Integer] duration How many seconds to background the app for. @@ -772,7 +770,6 @@ def shake @bridge.shake end - # @deprecated Use 'mobile: getDeviceTime' extension instead. # Get the time on the device # # @param [String] format The set of format specifiers. Read https://momentjs.com/docs/ to get @@ -786,7 +783,6 @@ def shake # @driver.device_time "YYYY-MM-DD" #=> "2018-06-12" # def device_time(format = nil) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: getDeviceTime' extension instead" @bridge.device_time(format) end diff --git a/lib/appium_lib_core/common/device/device.rb b/lib/appium_lib_core/common/device/device.rb index 7959828d..cf9b00f2 100644 --- a/lib/appium_lib_core/common/device/device.rb +++ b/lib/appium_lib_core/common/device/device.rb @@ -24,7 +24,8 @@ def shake def device_time(format = nil) arg = {} arg[:format] = format unless format.nil? - execute :device_time, {}, arg + + execute_script 'mobile:getDeviceTime', arg end end # module Device end # module Device diff --git a/test/unit/android/device/w3c/commands_test.rb b/test/unit/android/device/w3c/commands_test.rb index f03ebe5d..aa62625a 100644 --- a/test/unit/android/device/w3c/commands_test.rb +++ b/test/unit/android/device/w3c/commands_test.rb @@ -47,23 +47,23 @@ def test_shake end def test_device_time - stub_request(:get, "#{SESSION}/appium/device/system_time") - .with(body: {}.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getDeviceTime', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 'device time' }.to_json) @driver.device_time - assert_requested(:get, "#{SESSION}/appium/device/system_time", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_device_time_with_format - stub_request(:get, "#{SESSION}/appium/device/system_time") - .with(body: { format: 'YYYY-MM-DD' }.to_json) + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:getDeviceTime', args: [{ format: 'YYYY-MM-DD' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 'device time' }.to_json) @driver.device_time('YYYY-MM-DD') - assert_requested(:get, "#{SESSION}/appium/device/system_time", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_open_notifications From e983e0e002a7197bef8116da2b8daad5dc80c60d Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 13:24:34 -0700 Subject: [PATCH 11/19] apply more --- lib/appium_lib_core/common/base/driver.rb | 8 ----- lib/appium_lib_core/common/command.rb | 1 - lib/appium_lib_core/common/device/device.rb | 2 +- .../common/device/device_lock.rb | 6 ++-- test/unit/android/device/w3c/commands_test.rb | 5 ++-- .../android/device/w3c/device_lock_test.rb | 30 ++++++++++++++----- 6 files changed, 29 insertions(+), 23 deletions(-) diff --git a/lib/appium_lib_core/common/base/driver.rb b/lib/appium_lib_core/common/base/driver.rb index c2f9ac6d..a8d4254d 100644 --- a/lib/appium_lib_core/common/base/driver.rb +++ b/lib/appium_lib_core/common/base/driver.rb @@ -221,7 +221,6 @@ def key_action(async: false) ) end - # @deprecated Use 'mobile: lock' extension instead. # Lock the device # @return [String] # @@ -232,11 +231,9 @@ def key_action(async: false) # # Block other commands during locking the device. # def lock(duration = nil) - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: lock' extension instead" @bridge.lock(duration) end - # @deprecated Use 'mobile: isLocked' extension instead. # Check current device status is weather locked or not # # @example @@ -245,12 +242,10 @@ def lock(duration = nil) # @driver.locked? # def locked? - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: isLocked' extension instead" @bridge.device_locked? end alias device_locked? locked? - # @deprecated Use 'mobile: unlock' extension instead. # Unlock the device # # @example @@ -258,7 +253,6 @@ def locked? # @driver.unlock # def unlock - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: unlock' extension instead" @bridge.unlock end @@ -758,7 +752,6 @@ def stop_and_save_recording_screen(file_path) @bridge.stop_and_save_recording_screen(file_path) end - # @deprecated Use 'mobile: shake' extension instead. # Cause the device to shake # # @example @@ -766,7 +759,6 @@ def stop_and_save_recording_screen(file_path) # @driver.shake # def shake - ::Appium::Logger.warn "[DEPRECATION] Please use 'mobile: shake' extension instead" @bridge.shake end diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index 9de3ee9e..6a95e399 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -192,7 +192,6 @@ module Commands app_installed?: [:post, 'session/:session_id/appium/device/app_installed'], activate_app: [:post, 'session/:session_id/appium/device/activate_app'], terminate_app: [:post, 'session/:session_id/appium/device/terminate_app'], - shake: [:post, 'session/:session_id/appium/device/shake'], push_file: [:post, 'session/:session_id/appium/device/push_file'], pull_file: [:post, 'session/:session_id/appium/device/pull_file'], pull_folder: [:post, 'session/:session_id/appium/device/pull_folder'], diff --git a/lib/appium_lib_core/common/device/device.rb b/lib/appium_lib_core/common/device/device.rb index cf9b00f2..fa19dd67 100644 --- a/lib/appium_lib_core/common/device/device.rb +++ b/lib/appium_lib_core/common/device/device.rb @@ -18,7 +18,7 @@ class Base module Device module Device def shake - execute :shake + execute_script 'mobile:shake', {} end def device_time(format = nil) diff --git a/lib/appium_lib_core/common/device/device_lock.rb b/lib/appium_lib_core/common/device/device_lock.rb index fdfb2951..9fb61b9c 100644 --- a/lib/appium_lib_core/common/device/device_lock.rb +++ b/lib/appium_lib_core/common/device/device_lock.rb @@ -19,15 +19,15 @@ module Device module DeviceLock def lock(duration = nil) opts = duration ? { seconds: duration } : {} - execute :lock, {}, opts + execute_script 'mobile:lock', opts end def device_locked? - execute :device_locked? + execute_script 'mobile:isLocked', {} end def unlock - execute :unlock + execute_script 'mobile:unlock', {} end end # module DeviceLock end # module Device diff --git a/test/unit/android/device/w3c/commands_test.rb b/test/unit/android/device/w3c/commands_test.rb index aa62625a..1a04d70a 100644 --- a/test/unit/android/device/w3c/commands_test.rb +++ b/test/unit/android/device/w3c/commands_test.rb @@ -38,12 +38,13 @@ def test_delete end def test_shake - stub_request(:post, "#{SESSION}/appium/device/shake") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:shake', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) @driver.shake - assert_requested(:post, "#{SESSION}/appium/device/shake", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_device_time diff --git a/test/unit/android/device/w3c/device_lock_test.rb b/test/unit/android/device/w3c/device_lock_test.rb index 8240aa79..3fa224f7 100644 --- a/test/unit/android/device/w3c/device_lock_test.rb +++ b/test/unit/android/device/w3c/device_lock_test.rb @@ -29,39 +29,53 @@ def setup end def test_device_locked? - stub_request(:post, "#{SESSION}/appium/device/is_locked") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:isLocked', args: [{}] }) .to_return(headers: HEADER, status: 200, body: { value: 'true' }.to_json) @driver.device_locked? - assert_requested(:post, "#{SESSION}/appium/device/is_locked", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_locked? - stub_request(:post, "#{SESSION}/appium/device/is_locked") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:isLocked', args: [{}] }) .to_return(headers: HEADER, status: 200, body: { value: 'true' }.to_json) @driver.locked? - assert_requested(:post, "#{SESSION}/appium/device/is_locked", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_unlock - stub_request(:post, "#{SESSION}/appium/device/unlock") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:unlock', args: [{}] }) .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) @driver.unlock - assert_requested(:post, "#{SESSION}/appium/device/unlock", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) + end + + def test_lock_no_duration + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:lock', args: [{}] }) + .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) + + @driver.lock + + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end def test_lock - stub_request(:post, "#{SESSION}/appium/device/lock") + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile:lock', args: [{ seconds: 5 }] }) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.lock 5 - assert_requested(:post, "#{SESSION}/appium/device/lock", times: 1) + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) end end # class DeviceLockTest end # module W3C From ffae831c8f7c800fe58018c8e2018022d6e2d90d Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 16:38:23 -0700 Subject: [PATCH 12/19] fix a few --- lib/appium_lib_core/common/device/keyevent.rb | 6 +++--- lib/appium_lib_core/ios/device/clipboard.rb | 4 ++-- .../functional/android/android/device_test.rb | 20 ------------------- test/unit/android/device/w3c/keyboard_test.rb | 11 ++++++---- 4 files changed, 12 insertions(+), 29 deletions(-) diff --git a/lib/appium_lib_core/common/device/keyevent.rb b/lib/appium_lib_core/common/device/keyevent.rb index 223d1251..1ef44704 100644 --- a/lib/appium_lib_core/common/device/keyevent.rb +++ b/lib/appium_lib_core/common/device/keyevent.rb @@ -32,18 +32,18 @@ def press_keycode(key, metastate: [], flags: []) args[:metastate] = metastate.reduce(0) { |acc, meta| acc | meta } unless metastate.empty? args[:flags] = flags.reduce(0) { |acc, flag| acc | flag } unless flags.empty? - execute_script 'mobile:pressKeyCode', args + execute_script 'mobile:pressKey', args end def long_press_keycode(key, metastate: [], flags: []) raise ::Appium::Core::Error::ArgumentError, 'flags should be Array' unless flags.is_a? Array raise ::Appium::Core::Error::ArgumentError, 'metastates should be Array' unless metastate.is_a? Array - args = { keycode: key } + args = { keycode: key, isLongPress: true } args[:metastate] = metastate.reduce(0) { |acc, meta| acc | meta } unless metastate.empty? args[:flags] = flags.reduce(0) { |acc, flag| acc | flag } unless flags.empty? - execute_script 'mobile:longPressKeyCode', args + execute_script 'mobile:pressKey', args end end # module KeyEvent end # module Device diff --git a/lib/appium_lib_core/ios/device/clipboard.rb b/lib/appium_lib_core/ios/device/clipboard.rb index d43a5b5b..2e9d0fbd 100644 --- a/lib/appium_lib_core/ios/device/clipboard.rb +++ b/lib/appium_lib_core/ios/device/clipboard.rb @@ -29,7 +29,7 @@ def get_clipboard(content_type: :plaintext) params = { contentType: content_type } - data = execute(:get_clipboard, {}, params) + data = execute_script 'mobile:getClipboard', params Base64.decode64 data end end @@ -46,7 +46,7 @@ def set_clipboard(content:, content_type: :plaintext) content: Base64.strict_encode64(content) } - execute(:set_clipboard, {}, params) + execute_script 'mobile:setClipboard', params end end end diff --git a/test/functional/android/android/device_test.rb b/test/functional/android/android/device_test.rb index 9e7e21b9..ca8e2d1e 100644 --- a/test/functional/android/android/device_test.rb +++ b/test/functional/android/android/device_test.rb @@ -151,26 +151,6 @@ def test_app_management @driver.wait_until { assert @driver.app_state('io.appium.android.apis') == :running_in_foreground } end - def test_start_activity - e = @driver.wait_until(&:current_activity) - assert_equal '.ApiDemos', e - - @driver.start_activity app_package: 'io.appium.android.apis', - app_activity: '.accessibility.AccessibilityNodeProviderActivity' - e = @driver.wait_until(&:current_activity) - assert true, e.include?('Node') - - # Espresso cannot launch my root launched activity: https://github.com/appium/appium-espresso-driver/pull/378#discussion_r250034209 - return if @@core.automation_name == :espresso - - @driver.start_activity app_package: 'com.android.settings', app_activity: '.Settings', - app_wait_package: 'com.android.settings', app_wait_activity: '.Settings' - e = @driver.wait_until(&:current_activity) - assert true, e.include?('Settings') - - @driver.start_activity app_package: 'io.appium.android.apis', app_activity: '.ApiDemos' - end - def test_current_package e = @driver.wait_until(&:current_package) assert_equal 'io.appium.android.apis', e diff --git a/test/unit/android/device/w3c/keyboard_test.rb b/test/unit/android/device/w3c/keyboard_test.rb index 50c2ca1c..9eabb2a5 100644 --- a/test/unit/android/device/w3c/keyboard_test.rb +++ b/test/unit/android/device/w3c/keyboard_test.rb @@ -51,7 +51,7 @@ def test_hide_keyboard # keypress def test_press_keycode stub_request(:post, "#{SESSION}/execute/sync") - .with(body: { script: 'mobile:pressKeyCode', args: [{ keycode: 86 }] }.to_json) + .with(body: { script: 'mobile:pressKey', args: [{ keycode: 86 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.press_keycode 86 @@ -62,7 +62,7 @@ def test_press_keycode # keypress def test_press_keycode_with_flags stub_request(:post, "#{SESSION}/execute/sync") - .with(body: { script: 'mobile:pressKeyCode', args: [{ keycode: 86, metastate: 2_097_153, flags: 44 }] }.to_json) + .with(body: { script: 'mobile:pressKey', args: [{ keycode: 86, metastate: 2_097_153, flags: 44 }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) # metastate is META_SHIFT_ON and META_NUM_LOCK_ON @@ -89,7 +89,7 @@ def test_press_keycode_with_flags_with_wrong_metastate # keypress def test_long_press_keycode stub_request(:post, "#{SESSION}/execute/sync") - .with(body: { script: 'mobile:longPressKeyCode', args: [{ keycode: 86 }] }.to_json) + .with(body: { script: 'mobile:pressKey', args: [{ keycode: 86, isLongPress: true }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.long_press_keycode 86 @@ -100,7 +100,10 @@ def test_long_press_keycode # keypress def test_long_press_keycodewith_flags stub_request(:post, "#{SESSION}/execute/sync") - .with(body: { script: 'mobile:longPressKeyCode', args: [{ keycode: 86, metastate: 1, flags: 36 }] }.to_json) + .with(body: { + script: 'mobile:pressKey', + args: [{ keycode: 86, isLongPress: true, metastate: 1, flags: 36 }] + }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) # metastate is META_SHIFT_ON From 0306c90ecc6bc4623cc4a152a834c97fd121f92f Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 18:00:25 -0700 Subject: [PATCH 13/19] improve test --- lib/appium_lib_core/common/command.rb | 3 --- test/functional/android/android/device_test.rb | 14 +++++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index 6a95e399..7ba6b9f3 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -183,9 +183,6 @@ module Commands set_context: [:post, 'session/:session_id/context'], current_context: [:get, 'session/:session_id/context'], - device_locked?: [:post, 'session/:session_id/appium/device/is_locked'], - unlock: [:post, 'session/:session_id/appium/device/unlock'], - lock: [:post, 'session/:session_id/appium/device/lock'], device_time: [:get, 'session/:session_id/appium/device/system_time'], install_app: [:post, 'session/:session_id/appium/device/install_app'], remove_app: [:post, 'session/:session_id/appium/device/remove_app'], diff --git a/test/functional/android/android/device_test.rb b/test/functional/android/android/device_test.rb index ca8e2d1e..e13e1ef6 100644 --- a/test/functional/android/android/device_test.rb +++ b/test/functional/android/android/device_test.rb @@ -49,9 +49,9 @@ def test_shake end def test_lock_unlock - @driver.lock + @driver.lock 0 # Unstable on CI - @@core.wait { assert @@driver.device_locked? } unless ci? + @@core.wait { assert @driver.device_locked? } unless ci? @driver.unlock @driver.wait_until { |d| assert !d.device_locked? } @@ -208,9 +208,9 @@ def test_open_notifications # test & comments from https://github.com/appium/appium/blob/1.x/test/functional/android/apidemos/notifications-specs.js#L19 # get to the notification page - @@core.wait { scroll_to('App').click } + @@core.wait { @driver.find_element(:accessibility_id, 'App').click } @@core.wait { scroll_to('Notification').click } - @@core.wait { scroll_to('Status Bar').click } + @@core.wait { @driver.find_element(:accessibility_id, 'Status Bar').click } # create a notification @@core.wait { @driver.find_element :accessibility_id, ':-|' }.click @driver.open_notifications @@ -225,7 +225,7 @@ def test_open_notifications end # should see the notification - @@core.wait_true { text 'Mood ring' } + @@core.wait_true { @driver.find_element :xpath, '//*[@text="Mood ring"]' } # return to app @driver.back # should be able to see elements from app @@ -291,10 +291,6 @@ def resource_id(string, on_match) resource_id = %r{^[a-zA-Z_][a-zA-Z0-9._]*:[^\/]+\/\S+$} string.match(resource_id) ? on_match : '' end - - def text(value) - @driver.find_element :uiautomator, "new UiSelector().className(\"android.widget.TextView\").text(\"#{value}\");" - end end end end From 07d4649a44e8a4b83d1d92f5f1a0bb3315c9f16f Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 18:30:38 -0700 Subject: [PATCH 14/19] revert bad removal --- lib/appium_lib_core/common/command.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index 7ba6b9f3..7b44a8ce 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -123,6 +123,7 @@ module Commands element_click: [:post, 'session/:session_id/element/:id/click'], element_tap: [:post, 'session/:session_id/element/:id/tap'], element_clear: [:post, 'session/:session_id/element/:id/clear'], + element_send_keys: [:post, 'session/:session_id/element/:id/value'], # # alerts From 2f667c0ee841ea9faebb4b4c8996da0860ea5b80 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 23:08:44 -0700 Subject: [PATCH 15/19] update rbs --- .../appium_lib_core/common/base/driver.rbs | 4 +--- .../common/base/has_network_connection.rbs | 19 ------------------- test/test_helper.rb | 4 ++-- 3 files changed, 3 insertions(+), 24 deletions(-) delete mode 100644 sig/lib/appium_lib_core/common/base/has_network_connection.rbs diff --git a/sig/lib/appium_lib_core/common/base/driver.rbs b/sig/lib/appium_lib_core/common/base/driver.rbs index 956446d5..cb13f5d9 100644 --- a/sig/lib/appium_lib_core/common/base/driver.rbs +++ b/sig/lib/appium_lib_core/common/base/driver.rbs @@ -32,8 +32,6 @@ module Appium include Base::HasLocation - include Base::HasNetworkConnection - include Core::Waitable attr_reader bridge: untyped @@ -62,7 +60,7 @@ module Appium def unlock: () -> untyped - def hide_keyboard: (?untyped? close_key, ?untyped? strategy) -> untyped + def hide_keyboard: (?untyped? close_key) -> untyped def keyboard_shown?: () -> untyped diff --git a/sig/lib/appium_lib_core/common/base/has_network_connection.rbs b/sig/lib/appium_lib_core/common/base/has_network_connection.rbs deleted file mode 100644 index 2b9b562f..00000000 --- a/sig/lib/appium_lib_core/common/base/has_network_connection.rbs +++ /dev/null @@ -1,19 +0,0 @@ -module Appium - module Core - class Base - module HasNetworkConnection - def network_connection_type: () -> untyped - - def network_connection_type=: (untyped connection_type) -> untyped - - private - - def type_to_values: () -> Hash[Symbol, Integer] - - def values_to_type: () -> untyped - - def valid_type?: (untyped type) -> untyped - end - end - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index 3833258a..ad472ddb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -211,9 +211,9 @@ def device_name(os_version, platform_name, wda_local_port) 'Apple TV' else name = if over_ios13?(os_version) - 'iPhone 15 Plus' + 'iPhone 15 Pro' else - 'iPhone 15 Pro Max' + 'iPhone 15 Pro' end parallel? ? "#{name} - #{wda_local_port}" : name From 3a0c95887c465bc3e5c10d5cba02c3f05a5073df Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 23:20:02 -0700 Subject: [PATCH 16/19] revert helper --- lib/appium_lib_core/android/device.rb | 9 +++++++++ test/test_helper.rb | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index a6b87575..cc65319e 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -71,6 +71,15 @@ module Device # @driver.get_display_density # 320 # + # @!method location + # Get the location of the device. + # + # @return [::Appium::Location] + # + # @example + # + # driver.location #=> ::Appium::Location.new(10, 10, 10) + # # @!method location= # Set the [::Appium::Location] of the device. # diff --git a/test/test_helper.rb b/test/test_helper.rb index ad472ddb..3833258a 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -211,9 +211,9 @@ def device_name(os_version, platform_name, wda_local_port) 'Apple TV' else name = if over_ios13?(os_version) - 'iPhone 15 Pro' + 'iPhone 15 Plus' else - 'iPhone 15 Pro' + 'iPhone 15 Pro Max' end parallel? ? "#{name} - #{wda_local_port}" : name From 7ecef5e3fa9f09b36fd6ff502f70530380cb24c1 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 23:28:55 -0700 Subject: [PATCH 17/19] fix typo --- lib/appium_lib_core/android/device/emulator.rb | 2 +- test/unit/android/device/w3c/commands_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/appium_lib_core/android/device/emulator.rb b/lib/appium_lib_core/android/device/emulator.rb index 3c441dda..d86d02a5 100644 --- a/lib/appium_lib_core/android/device/emulator.rb +++ b/lib/appium_lib_core/android/device/emulator.rb @@ -146,7 +146,7 @@ def gsm_voice(state) raise ::Appium::Core::Error::ArgumentError, "The state should be member of #{GSM_VOICE_STATES}. Not #{state}." end - execute_script 'mobile:gsmVoic', { state: state } + execute_script 'mobile:gsmVoice', { state: state } end end diff --git a/test/unit/android/device/w3c/commands_test.rb b/test/unit/android/device/w3c/commands_test.rb index 1a04d70a..99d613d9 100644 --- a/test/unit/android/device/w3c/commands_test.rb +++ b/test/unit/android/device/w3c/commands_test.rb @@ -318,7 +318,7 @@ def test_gsm_signal def test_gsm_voice stub_request(:post, "#{SESSION}/execute/sync") - .with(body: { script: 'mobile:gsmVoic', args: [{ state: 'on' }] }.to_json) + .with(body: { script: 'mobile:gsmVoice', args: [{ state: 'on' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.gsm_voice :on From 7be8d806b6f475cdab3060399ce63ec9614f1e4b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Sun, 16 Mar 2025 23:33:43 -0700 Subject: [PATCH 18/19] correct update --- lib/appium_lib_core/android/device.rb | 6 +----- lib/appium_lib_core/android/device/emulator.rb | 2 +- lib/appium_lib_core/common/base/driver.rb | 4 ---- test/unit/android/device/w3c/commands_test.rb | 2 +- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index cc65319e..ac817180 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -114,19 +114,15 @@ module Device # @driver.toggle_location_services # - # @!method hide_keyboard(close_key = nil, strategy = nil) + # @!method hide_keyboard(close_key = nil) # Hide the onscreen keyboard # @param [String] close_key The name of the key which closes the keyboard. # Defaults to 'Done' for iOS(except for XCUITest). - # @param [Symbol] strategy The symbol of the strategy which closes the keyboard. - # XCUITest ignore this argument. - # Default for iOS is +:pressKey+. Default for Android is +:tapOutside+. # # @example # # @driver.hide_keyboard # Close a keyboard with the 'Done' button # @driver.hide_keyboard('Finished') # Close a keyboard with the 'Finished' button - # @driver.hide_keyboard(nil, :tapOutside) # Close a keyboard with tapping out side of keyboard # # @!method get_performance_data_types diff --git a/lib/appium_lib_core/android/device/emulator.rb b/lib/appium_lib_core/android/device/emulator.rb index d86d02a5..548cddbf 100644 --- a/lib/appium_lib_core/android/device/emulator.rb +++ b/lib/appium_lib_core/android/device/emulator.rb @@ -157,7 +157,7 @@ def set_network_speed(netspeed) "The netspeed should be member of #{NET_SPEED}. Not #{netspeed}." end - execute_script 'mobile:networkSpee', { speed: netspeed } + execute_script 'mobile:networkSpeed', { speed: netspeed } end end diff --git a/lib/appium_lib_core/common/base/driver.rb b/lib/appium_lib_core/common/base/driver.rb index a8d4254d..75e34a89 100644 --- a/lib/appium_lib_core/common/base/driver.rb +++ b/lib/appium_lib_core/common/base/driver.rb @@ -259,15 +259,11 @@ def unlock # Hide the onscreen keyboard # @param [String] close_key The name of the key which closes the keyboard. # Defaults to 'Done' for iOS(except for XCUITest). - # @param [Symbol] strategy The symbol of the strategy which closes the keyboard. - # XCUITest ignore this argument. - # Default for iOS is +:pressKey+. Default for Android is +:tapOutside+. # # @example # # @driver.hide_keyboard # Close a keyboard with the 'Done' button # @driver.hide_keyboard('Finished') # Close a keyboard with the 'Finished' button - # @driver.hide_keyboard(nil, :tapOutside) # Close a keyboard with tapping out side of keyboard # def hide_keyboard(close_key = nil) @bridge.hide_keyboard close_key diff --git a/test/unit/android/device/w3c/commands_test.rb b/test/unit/android/device/w3c/commands_test.rb index 99d613d9..0b496b16 100644 --- a/test/unit/android/device/w3c/commands_test.rb +++ b/test/unit/android/device/w3c/commands_test.rb @@ -328,7 +328,7 @@ def test_gsm_voice def test_network_speed stub_request(:post, "#{SESSION}/execute/sync") - .with(body: { script: 'mobile:networkSpee', args: [{ speed: 'gsm' }] }.to_json) + .with(body: { script: 'mobile:networkSpeed', args: [{ speed: 'gsm' }] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: '' }.to_json) @driver.set_network_speed :gsm From 5c29fababe5e179d1205ee67be635e0834b3aabc Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Mon, 17 Mar 2025 00:26:35 -0700 Subject: [PATCH 19/19] update a test case --- test/functional/android/android/mobile_commands_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/functional/android/android/mobile_commands_test.rb b/test/functional/android/android/mobile_commands_test.rb index a9061776..05b6cf48 100644 --- a/test/functional/android/android/mobile_commands_test.rb +++ b/test/functional/android/android/mobile_commands_test.rb @@ -213,7 +213,7 @@ def test_webatom el = @core.wait { @driver.find_element(:id, 'wv1') } @driver.execute_script 'mobile: webAtoms', { - webviewElement: el.id, + webviewEl: el.id, forceJavascriptEnabled: true, methodChain: [ { name: 'withElement', atom: { name: 'findElement', locator: { using: 'ID', value: 'i_am_a_textbox' } } },