From 394dafe8668170552e5a0f40d93e764e78adf3d8 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 2 May 2018 01:37:38 +0900 Subject: [PATCH 1/9] add battery info --- lib/appium_lib_core/android/device.rb | 16 ++++++++++++++ lib/appium_lib_core/device/battery_status.rb | 23 ++++++++++++++++++++ lib/appium_lib_core/ios/xcuitest/device.rb | 15 +++++++++++++ lib/appium_lib_core/ios_xcuitest.rb | 2 ++ test/unit/ios/device_test.rb | 11 ++++++++++ test/unit/ios/device_w3c_test.rb | 11 ++++++++++ 6 files changed, 78 insertions(+) create mode 100644 lib/appium_lib_core/device/battery_status.rb diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index 9654e28e..b5027989 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -382,10 +382,26 @@ def get_performance_data(package_name:, data_type:, data_read_timeout: 1000) add_screen_recording add_clipboard Emulator.emulator_commands + add_battery_info end private + def add_battery_info + ::Appium::Core::Device.add_endpoint_method(:get_battery_info) do + def get_clipboard(content_type: :plaintext) + unless ::Appium::Core::Device::Clipboard::CONTENT_TYPE.member?(content_type) + raise "content_type should be #{::Appium::Core::Device::Clipboard::CONTENT_TYPE}" + end + + params = { contentType: content_type } + + data = execute(:get_clipboard, {}, params) + Base64.decode64 data + end + end + end + def add_screen_recording Appium::Core::Device.add_endpoint_method(:start_recording_screen) do # rubocop:disable Metrics/ParameterLists diff --git a/lib/appium_lib_core/device/battery_status.rb b/lib/appium_lib_core/device/battery_status.rb new file mode 100644 index 00000000..f6fb0325 --- /dev/null +++ b/lib/appium_lib_core/device/battery_status.rb @@ -0,0 +1,23 @@ +module Appium + module Core + module Device + module BatteryStatus + ANDROID = [ + :undefined, # 0 + :unknown, # 1 + :charging, # 2 + :discharging, # 3 + :not_charging,# 4 + :full # 5 + ].freeze + + IOS = [ + :unknown, # 0 + :unplugged, # 1 + :charging, # 2 + :full # 3 + ].freeze + end + end + end +end diff --git a/lib/appium_lib_core/ios/xcuitest/device.rb b/lib/appium_lib_core/ios/xcuitest/device.rb index 96e0d912..814f7137 100644 --- a/lib/appium_lib_core/ios/xcuitest/device.rb +++ b/lib/appium_lib_core/ios/xcuitest/device.rb @@ -143,10 +143,25 @@ def background_app(duration = 0) add_performance add_screen_recording + add_battery_info end private + def add_battery_info + Appium::Core::Device.add_endpoint_method(:battery_info) do + def battery_info + response = execute_script 'mobile: batteryInfo', {} + case response + when 1, 2, 3 + ::Appium::Core::Device::BatteryStatus::IOS[response] + else + ::Appium::Core::Device::BatteryStatus::IOS[0] # :unknown + end + end + end + end + def add_performance Appium::Core::Device.add_endpoint_method(:start_performance_record) do def start_performance_record(timeout: 300_000, profile_name: 'Activity Monitor', pid: nil) diff --git a/lib/appium_lib_core/ios_xcuitest.rb b/lib/appium_lib_core/ios_xcuitest.rb index 00123b6d..e26c37ad 100644 --- a/lib/appium_lib_core/ios_xcuitest.rb +++ b/lib/appium_lib_core/ios_xcuitest.rb @@ -5,3 +5,5 @@ require_relative 'ios/xcuitest/search_context' require_relative 'ios/xcuitest/device' require_relative 'ios/xcuitest/bridge' + +require_relative 'device/battery_status' diff --git a/test/unit/ios/device_test.rb b/test/unit/ios/device_test.rb index a16da4a3..b15a67ac 100644 --- a/test/unit/ios/device_test.rb +++ b/test/unit/ios/device_test.rb @@ -127,6 +127,17 @@ def test_stop_recording_screen_custom assert_requested(:post, "#{SESSION}/appium/stop_recording_screen", times: 1) end + + def test_get_battery_info + stub_request(:post, "#{SESSION}/execute") + .with(body: {script: 'mobile: batteryInfo', args: [{}]}.to_json) + .to_return(headers: HEADER, status: 200, body: { value: 3 }.to_json) + + info = @driver.battery_info + + assert_requested(:post, "#{SESSION}/execute", times: 1) + assert_equal :full, info + end end end end diff --git a/test/unit/ios/device_w3c_test.rb b/test/unit/ios/device_w3c_test.rb index ff7dc6d8..0641566a 100644 --- a/test/unit/ios/device_w3c_test.rb +++ b/test/unit/ios/device_w3c_test.rb @@ -115,6 +115,17 @@ def test_stop_recording_screen_custom assert_requested(:post, "#{SESSION}/appium/stop_recording_screen", times: 1) end + + def test_get_battery_info + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: {script: 'mobile: batteryInfo', args: [{}]}.to_json) + .to_return(headers: HEADER, status: 200, body: { value: 1 }.to_json) + + info = @driver.battery_info + + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) + assert_equal :unplugged, info + end end end end From f412189fe35cd284dbeb39464a970bec58ee3b2f Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 2 May 2018 01:40:17 +0900 Subject: [PATCH 2/9] fix rubocop --- lib/appium_lib_core/device/battery_status.rb | 20 ++++++++++---------- test/unit/ios/device_test.rb | 2 +- test/unit/ios/device_w3c_test.rb | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/appium_lib_core/device/battery_status.rb b/lib/appium_lib_core/device/battery_status.rb index f6fb0325..1c3885fe 100644 --- a/lib/appium_lib_core/device/battery_status.rb +++ b/lib/appium_lib_core/device/battery_status.rb @@ -3,19 +3,19 @@ module Core module Device module BatteryStatus ANDROID = [ - :undefined, # 0 - :unknown, # 1 - :charging, # 2 - :discharging, # 3 - :not_charging,# 4 - :full # 5 + :undefined, # 0, dummy + :unknown, # 1 + :charging, # 2 + :discharging, # 3 + :not_charging, # 4 + :full # 5 ].freeze IOS = [ - :unknown, # 0 - :unplugged, # 1 - :charging, # 2 - :full # 3 + :unknown, # 0 + :unplugged, # 1 + :charging, # 2 + :full # 3 ].freeze end end diff --git a/test/unit/ios/device_test.rb b/test/unit/ios/device_test.rb index b15a67ac..b11fc877 100644 --- a/test/unit/ios/device_test.rb +++ b/test/unit/ios/device_test.rb @@ -130,7 +130,7 @@ def test_stop_recording_screen_custom def test_get_battery_info stub_request(:post, "#{SESSION}/execute") - .with(body: {script: 'mobile: batteryInfo', args: [{}]}.to_json) + .with(body: { script: 'mobile: batteryInfo', args: [{}] }.to_json) .to_return(headers: HEADER, status: 200, body: { value: 3 }.to_json) info = @driver.battery_info diff --git a/test/unit/ios/device_w3c_test.rb b/test/unit/ios/device_w3c_test.rb index 0641566a..9ac4f919 100644 --- a/test/unit/ios/device_w3c_test.rb +++ b/test/unit/ios/device_w3c_test.rb @@ -118,8 +118,8 @@ def test_stop_recording_screen_custom def test_get_battery_info stub_request(:post, "#{SESSION}/execute/sync") - .with(body: {script: 'mobile: batteryInfo', args: [{}]}.to_json) - .to_return(headers: HEADER, status: 200, body: { value: 1 }.to_json) + .with(body: { script: 'mobile: batteryInfo', args: [{}] }.to_json) + .to_return(headers: HEADER, status: 200, body: { value: 1 }.to_json) info = @driver.battery_info From 0d02d022d048faafb5a8da31db6771184cd4d653 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 2 May 2018 02:45:49 +0900 Subject: [PATCH 3/9] add android --- lib/appium_lib_core/android/device.rb | 16 ---------- .../android/uiautomator2/bridge.rb | 1 + .../android/uiautomator2/device.rb | 32 +++++++++++++++++++ lib/appium_lib_core/android_uiautomator2.rb | 2 ++ lib/appium_lib_core/ios/xcuitest/device.rb | 14 ++++---- test/unit/android/device_test.rb | 12 +++++++ test/unit/android/device_w3c_test.rb | 12 +++++++ test/unit/ios/device_test.rb | 5 +-- test/unit/ios/device_w3c_test.rb | 5 +-- 9 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 lib/appium_lib_core/android/uiautomator2/device.rb diff --git a/lib/appium_lib_core/android/device.rb b/lib/appium_lib_core/android/device.rb index b5027989..9654e28e 100644 --- a/lib/appium_lib_core/android/device.rb +++ b/lib/appium_lib_core/android/device.rb @@ -382,26 +382,10 @@ def get_performance_data(package_name:, data_type:, data_read_timeout: 1000) add_screen_recording add_clipboard Emulator.emulator_commands - add_battery_info end private - def add_battery_info - ::Appium::Core::Device.add_endpoint_method(:get_battery_info) do - def get_clipboard(content_type: :plaintext) - unless ::Appium::Core::Device::Clipboard::CONTENT_TYPE.member?(content_type) - raise "content_type should be #{::Appium::Core::Device::Clipboard::CONTENT_TYPE}" - end - - params = { contentType: content_type } - - data = execute(:get_clipboard, {}, params) - Base64.decode64 data - end - end - end - def add_screen_recording Appium::Core::Device.add_endpoint_method(:start_recording_screen) do # rubocop:disable Metrics/ParameterLists diff --git a/lib/appium_lib_core/android/uiautomator2/bridge.rb b/lib/appium_lib_core/android/uiautomator2/bridge.rb index f10ae1f5..5e1074c9 100644 --- a/lib/appium_lib_core/android/uiautomator2/bridge.rb +++ b/lib/appium_lib_core/android/uiautomator2/bridge.rb @@ -6,6 +6,7 @@ module Bridge def self.for(target) target.extend Appium::Android::Device Core::Android::SearchContext.extend + target.extend Appium::Core::Android::Uiautomator2::Device end end end diff --git a/lib/appium_lib_core/android/uiautomator2/device.rb b/lib/appium_lib_core/android/uiautomator2/device.rb new file mode 100644 index 00000000..203321ca --- /dev/null +++ b/lib/appium_lib_core/android/uiautomator2/device.rb @@ -0,0 +1,32 @@ +module Appium + module Core + module Android + module Uiautomator2 + module Device + extend Forwardable + + class << self + def extended(_mod) + ::Appium::Core::Device.extend_webdriver_with_forwardable + + # Override + ::Appium::Core::Device.add_endpoint_method(:battery_info) do + def battery_info + response = execute_script 'mobile: batteryInfo', {} + + state = case response['state'] + when 1, 2, 3, 4, 5 + ::Appium::Core::Device::BatteryStatus::ANDROID[response['state']] + else + ::Appium::Core::Device::BatteryStatus::ANDROID[0] # :undefined + end + {state: state, level: response['level']} + end + end + end + end # class << self + end # module Device + end # module Uiautomator2 + end # module Android + end # module Core +end # module Appium diff --git a/lib/appium_lib_core/android_uiautomator2.rb b/lib/appium_lib_core/android_uiautomator2.rb index eaedd65f..0cf058cc 100644 --- a/lib/appium_lib_core/android_uiautomator2.rb +++ b/lib/appium_lib_core/android_uiautomator2.rb @@ -1,4 +1,6 @@ # loaded in common/driver.rb require_relative 'android/search_context' require_relative 'android/device' + require_relative 'android/uiautomator2/bridge' +require_relative 'android/uiautomator2/device' diff --git a/lib/appium_lib_core/ios/xcuitest/device.rb b/lib/appium_lib_core/ios/xcuitest/device.rb index 814f7137..fcca2a5c 100644 --- a/lib/appium_lib_core/ios/xcuitest/device.rb +++ b/lib/appium_lib_core/ios/xcuitest/device.rb @@ -152,12 +152,14 @@ def add_battery_info Appium::Core::Device.add_endpoint_method(:battery_info) do def battery_info response = execute_script 'mobile: batteryInfo', {} - case response - when 1, 2, 3 - ::Appium::Core::Device::BatteryStatus::IOS[response] - else - ::Appium::Core::Device::BatteryStatus::IOS[0] # :unknown - end + + state = case response['state'] + when 1, 2, 3 + ::Appium::Core::Device::BatteryStatus::IOS[response['state']] + else + ::Appium::Core::Device::BatteryStatus::IOS[0] # :unknown + end + {state: state, level: response['level']} end end end diff --git a/test/unit/android/device_test.rb b/test/unit/android/device_test.rb index 02371334..c5d57933 100644 --- a/test/unit/android/device_test.rb +++ b/test/unit/android/device_test.rb @@ -755,6 +755,18 @@ def test_image_comparison_get_images_similarity assert_requested(:post, "#{SESSION}/appium/compare_images", times: 1) end + + def test_get_battery_info + stub_request(:post, "#{SESSION}/execute") + .with(body: { script: 'mobile: batteryInfo', args: [{}] }.to_json) + .to_return(headers: HEADER, status: 200, body: { value: { state: 2, level: 1.0 } }.to_json) + + info = @driver.battery_info + + assert_requested(:post, "#{SESSION}/execute", times: 1) + assert_equal :charging, info[:state] + assert_equal 1.0, info[:level] + end end end end diff --git a/test/unit/android/device_w3c_test.rb b/test/unit/android/device_w3c_test.rb index e1bfff54..8968d9a7 100644 --- a/test/unit/android/device_w3c_test.rb +++ b/test/unit/android/device_w3c_test.rb @@ -732,6 +732,18 @@ def test_image_comparison_get_images_similarity assert_requested(:post, "#{SESSION}/appium/compare_images", times: 1) end + + def test_get_battery_info + stub_request(:post, "#{SESSION}/execute/sync") + .with(body: { script: 'mobile: batteryInfo', args: [{}] }.to_json) + .to_return(headers: HEADER, status: 200, body: { value: { state: 5, level: 0.5 } }.to_json) + + info = @driver.battery_info + + assert_requested(:post, "#{SESSION}/execute/sync", times: 1) + assert_equal :full, info[:state] + assert_equal 0.5, info[:level] + end end end end diff --git a/test/unit/ios/device_test.rb b/test/unit/ios/device_test.rb index b11fc877..4e454af6 100644 --- a/test/unit/ios/device_test.rb +++ b/test/unit/ios/device_test.rb @@ -131,12 +131,13 @@ def test_stop_recording_screen_custom def test_get_battery_info stub_request(:post, "#{SESSION}/execute") .with(body: { script: 'mobile: batteryInfo', args: [{}] }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: 3 }.to_json) + .to_return(headers: HEADER, status: 200, body: { value: { state: 3, level: 1.0 } }.to_json) info = @driver.battery_info assert_requested(:post, "#{SESSION}/execute", times: 1) - assert_equal :full, info + assert_equal :full, info[:state] + assert_equal 1.0, info[:level] end end end diff --git a/test/unit/ios/device_w3c_test.rb b/test/unit/ios/device_w3c_test.rb index 9ac4f919..7c0530fb 100644 --- a/test/unit/ios/device_w3c_test.rb +++ b/test/unit/ios/device_w3c_test.rb @@ -119,12 +119,13 @@ def test_stop_recording_screen_custom def test_get_battery_info stub_request(:post, "#{SESSION}/execute/sync") .with(body: { script: 'mobile: batteryInfo', args: [{}] }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: 1 }.to_json) + .to_return(headers: HEADER, status: 200, body: { value: { state: 1, level: 0.5 } }.to_json) info = @driver.battery_info assert_requested(:post, "#{SESSION}/execute/sync", times: 1) - assert_equal :unplugged, info + assert_equal :unplugged, info[:state] + assert_equal 0.5, info[:level] end end end From e37f9c02a7e34be8a7ff61e366ce8fe3570a685e Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 2 May 2018 07:55:39 +0900 Subject: [PATCH 4/9] fix rubocop --- lib/appium_lib_core/android/uiautomator2/device.rb | 2 +- lib/appium_lib_core/ios/xcuitest/device.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/appium_lib_core/android/uiautomator2/device.rb b/lib/appium_lib_core/android/uiautomator2/device.rb index 203321ca..8d2ca456 100644 --- a/lib/appium_lib_core/android/uiautomator2/device.rb +++ b/lib/appium_lib_core/android/uiautomator2/device.rb @@ -20,7 +20,7 @@ def battery_info else ::Appium::Core::Device::BatteryStatus::ANDROID[0] # :undefined end - {state: state, level: response['level']} + { state: state, level: response['level'] } end end end diff --git a/lib/appium_lib_core/ios/xcuitest/device.rb b/lib/appium_lib_core/ios/xcuitest/device.rb index fcca2a5c..4502f76f 100644 --- a/lib/appium_lib_core/ios/xcuitest/device.rb +++ b/lib/appium_lib_core/ios/xcuitest/device.rb @@ -159,7 +159,7 @@ def battery_info else ::Appium::Core::Device::BatteryStatus::IOS[0] # :unknown end - {state: state, level: response['level']} + { state: state, level: response['level'] } end end end From 15327756188f78a770169d9b735f8452f0b3980e Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 2 May 2018 08:19:48 +0900 Subject: [PATCH 5/9] add docstring --- .../android/uiautomator2/device.rb | 23 ++++++++++++++++--- lib/appium_lib_core/ios/xcuitest/device.rb | 17 ++++++++++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lib/appium_lib_core/android/uiautomator2/device.rb b/lib/appium_lib_core/android/uiautomator2/device.rb index 8d2ca456..70bf18b3 100644 --- a/lib/appium_lib_core/android/uiautomator2/device.rb +++ b/lib/appium_lib_core/android/uiautomator2/device.rb @@ -5,11 +5,28 @@ module Uiautomator2 module Device extend Forwardable + # @since 1.6.0 + # @!method battery_info + # + # Get battery information. + # + # @return [Hash] Return battery level and battery state. + # Battery level in range [0.0, 1.0], where 1.0 means 100% charge. + # -1 is returned if the actual value cannot be retrieved from the system. + # Battery state. The following symbols are possible + # `:unknown, :charging, :discharging, :not_charging, :full` + # + # @example + # + # @driver.battery_info #=> { state: :charging, level: 0.7 } + # + + #### + ## class << self + #### + class << self def extended(_mod) - ::Appium::Core::Device.extend_webdriver_with_forwardable - - # Override ::Appium::Core::Device.add_endpoint_method(:battery_info) do def battery_info response = execute_script 'mobile: batteryInfo', {} diff --git a/lib/appium_lib_core/ios/xcuitest/device.rb b/lib/appium_lib_core/ios/xcuitest/device.rb index 4502f76f..96a714e9 100644 --- a/lib/appium_lib_core/ios/xcuitest/device.rb +++ b/lib/appium_lib_core/ios/xcuitest/device.rb @@ -109,6 +109,21 @@ module Device # @driver.get_performance_record # @driver.get_performance_record(save_file_path: './performance', profile_name: 'Activity Monitor') + # @since 1.6.0 + # @!method battery_info + # + # Get battery information. + # + # @return [Hash] Return battery level and battery state. + # Battery level in range [0.0, 1.0], where 1.0 means 100% charge. + # Battery state. The following symbols are possible + # `:unplugged, :charging, :full` + # + # @example + # + # @driver.battery_info #=> { state: :full, level: 0.7 } + # + # rubocop:enable Metrics/LineLength #### @@ -117,8 +132,6 @@ module Device class << self def extended(_mod) - ::Appium::Core::Device.extend_webdriver_with_forwardable - # Override ::Appium::Core::Device.add_endpoint_method(:hide_keyboard) do def hide_keyboard(close_key = nil, strategy = nil) From 4736dd4a28cd29eecb26d7b0204faf092d4e0648 Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Wed, 2 May 2018 08:23:05 +0900 Subject: [PATCH 6/9] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a26bba5..66ae4e27 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file. - `0, 1, 2, 3, 4` or `NOT_INSTALLED, NOT_RUNNING, RUNNING_IN_BACKGROUND_SUSPENDED, RUNNING_IN_BACKGROUND, RUNNING_IN_FOREGROUND` - After: Symbol. - `:not_installed, :not_running, :running_in_background_suspended, :running_in_background, :running_in_foreground` +- add `battery_info` to get battery information ### Bug fixes From 150d03082728b90fd3b957393c5b46312b58f6ee Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Sun, 6 May 2018 09:08:49 +0800 Subject: [PATCH 7/9] add func test --- lib/appium_lib_core/android/uiautomator2/device.rb | 9 +++++---- lib/appium_lib_core/ios/xcuitest/device.rb | 4 +++- test/functional/android/android/device_test.rb | 7 +++++++ test/functional/ios/ios/device_test.rb | 7 +++++++ 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/appium_lib_core/android/uiautomator2/device.rb b/lib/appium_lib_core/android/uiautomator2/device.rb index 70bf18b3..7fcbe092 100644 --- a/lib/appium_lib_core/android/uiautomator2/device.rb +++ b/lib/appium_lib_core/android/uiautomator2/device.rb @@ -11,8 +11,8 @@ module Device # Get battery information. # # @return [Hash] Return battery level and battery state. - # Battery level in range [0.0, 1.0], where 1.0 means 100% charge. - # -1 is returned if the actual value cannot be retrieved from the system. + # Battery level in range [0.0, 1.0], where 1.0 means 100% charge. -1 is returned + # if the actual value cannot be retrieved from the system. # Battery state. The following symbols are possible # `:unknown, :charging, :discharging, :not_charging, :full` # @@ -32,10 +32,11 @@ def battery_info response = execute_script 'mobile: batteryInfo', {} state = case response['state'] - when 1, 2, 3, 4, 5 + when 2, 3, 4, 5 ::Appium::Core::Device::BatteryStatus::ANDROID[response['state']] else - ::Appium::Core::Device::BatteryStatus::ANDROID[0] # :undefined + Appium::Logger.warn("The state is unknown or undefined: #{response['state']}") + ::Appium::Core::Device::BatteryStatus::ANDROID[1] # :unknown end { state: state, level: response['level'] } end diff --git a/lib/appium_lib_core/ios/xcuitest/device.rb b/lib/appium_lib_core/ios/xcuitest/device.rb index 96a714e9..124bb51f 100644 --- a/lib/appium_lib_core/ios/xcuitest/device.rb +++ b/lib/appium_lib_core/ios/xcuitest/device.rb @@ -115,7 +115,8 @@ module Device # Get battery information. # # @return [Hash] Return battery level and battery state. - # Battery level in range [0.0, 1.0], where 1.0 means 100% charge. + # Battery level in range [0.0, 1.0], where 1.0 means 100% charge. -1 is returned + # if the actual value cannot be retrieved from the system. # Battery state. The following symbols are possible # `:unplugged, :charging, :full` # @@ -170,6 +171,7 @@ def battery_info when 1, 2, 3 ::Appium::Core::Device::BatteryStatus::IOS[response['state']] else + Appium::Logger.warn("The state is unknown or undefined: #{response['state']}") ::Appium::Core::Device::BatteryStatus::IOS[0] # :unknown end { state: state, level: response['level'] } diff --git a/test/functional/android/android/device_test.rb b/test/functional/android/android/device_test.rb index e3a3dd03..ab32c079 100644 --- a/test/functional/android/android/device_test.rb +++ b/test/functional/android/android/device_test.rb @@ -389,6 +389,13 @@ def test_image_comparison_get_images_result File.delete 'get_images_result_visual.png' end + def test_battery_info + result = @@driver.battery_info + + assert !result[:state].nil? + assert !result[:level].nil? + end + private def scroll_to(text) diff --git a/test/functional/ios/ios/device_test.rb b/test/functional/ios/ios/device_test.rb index 4ee034ab..11ec1fe5 100644 --- a/test/functional/ios/ios/device_test.rb +++ b/test/functional/ios/ios/device_test.rb @@ -301,6 +301,13 @@ def test_image_comparison_get_images_result File.delete 'get_images_result_visual.png' end + + def test_battery_info + result = @@driver.battery_info + + assert !result[:state].nil? + assert !result[:level].nil? + end end end end From 69ac2c0748e60304c229455b3d4af16abe91694b Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Sun, 6 May 2018 10:47:30 +0800 Subject: [PATCH 8/9] move touch actions in common touch action directoly --- .../touch_action}/multi_touch.rb | 0 .../touch_action}/touch_actions.rb | 36 +++++++++---------- lib/appium_lib_core/device.rb | 4 +-- test/functional/ios/ios/device_test.rb | 6 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) rename lib/appium_lib_core/{device => common/touch_action}/multi_touch.rb (100%) rename lib/appium_lib_core/{device => common/touch_action}/touch_actions.rb (88%) diff --git a/lib/appium_lib_core/device/multi_touch.rb b/lib/appium_lib_core/common/touch_action/multi_touch.rb similarity index 100% rename from lib/appium_lib_core/device/multi_touch.rb rename to lib/appium_lib_core/common/touch_action/multi_touch.rb diff --git a/lib/appium_lib_core/device/touch_actions.rb b/lib/appium_lib_core/common/touch_action/touch_actions.rb similarity index 88% rename from lib/appium_lib_core/device/touch_actions.rb rename to lib/appium_lib_core/common/touch_action/touch_actions.rb index 7700ebe1..099ff581 100644 --- a/lib/appium_lib_core/device/touch_actions.rb +++ b/lib/appium_lib_core/common/touch_action/touch_actions.rb @@ -1,23 +1,23 @@ module Appium - # Perform a series of gestures, one after another. Gestures are chained - # together and only performed when `perform()` is called. Default is conducted by global driver. - # - # Each method returns the object itself, so calls can be chained. - # - # Consider to use W3C spec touch action like the followings. - # https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html - # https://github.com/appium/ruby_lib_core/blob/master/test/functional/android/webdriver/w3c_actions_test.rb - # https://github.com/appium/ruby_lib_core/blob/master/test/functional/ios/webdriver/w3c_actions_test.rb - # - # @example - # - # @driver = Appium::Core.for(self, opts).start_driver - # action = TouchAction.new(@driver).press(x: 45, y: 100).wait(5).release - # action.perform - # action = TouchAction.new(@driver).swipe(....) - # action.perform - # module Core + # Perform a series of gestures, one after another. Gestures are chained + # together and only performed when `perform()` is called. Default is conducted by global driver. + # + # Each method returns the object itself, so calls can be chained. + # + # Consider to use W3C spec touch action like the followings. + # https://seleniumhq.github.io/selenium/docs/api/rb/Selenium/WebDriver/W3CActionBuilder.html + # https://github.com/appium/ruby_lib_core/blob/master/test/functional/android/webdriver/w3c_actions_test.rb + # https://github.com/appium/ruby_lib_core/blob/master/test/functional/ios/webdriver/w3c_actions_test.rb + # + # @example + # + # @driver = Appium::Core.for(self, opts).start_driver + # action = TouchAction.new(@driver).press(x: 45, y: 100).wait(5).release + # action.perform + # action = TouchAction.new(@driver).swipe(....) + # action.perform + # class TouchAction ACTIONS = %i(move_to long_press double_tap two_finger_tap press release tap wait perform).freeze COMPLEX_ACTIONS = %i(swipe).freeze diff --git a/lib/appium_lib_core/device.rb b/lib/appium_lib_core/device.rb index a3432000..2c90c2b8 100644 --- a/lib/appium_lib_core/device.rb +++ b/lib/appium_lib_core/device.rb @@ -1,5 +1,5 @@ -require_relative 'device/touch_actions' -require_relative 'device/multi_touch' +require_relative 'common/touch_action/touch_actions' +require_relative 'common/touch_action/multi_touch' require_relative 'device/screen_record' require_relative 'device/app_state' require_relative 'device/clipboard_content_type' diff --git a/test/functional/ios/ios/device_test.rb b/test/functional/ios/ios/device_test.rb index 11ec1fe5..8b8f7a5a 100644 --- a/test/functional/ios/ios/device_test.rb +++ b/test/functional/ios/ios/device_test.rb @@ -44,11 +44,11 @@ def test_close_and_launch_app end def test_lock_unlock - @@driver.lock 5 - assert @@driver.device_locked? + @@driver.lock + @@core.wait { assert @@driver.device_locked? } @@driver.unlock - assert !@@driver.device_locked? + @@core.wait { assert !@@driver.device_locked? } end def test_background_reset From ac6bf1680f435de08d29501e77faba8941d4076e Mon Sep 17 00:00:00 2001 From: Kazuaki MATSUO Date: Sun, 6 May 2018 17:52:42 +0800 Subject: [PATCH 9/9] appends a limit for ios --- lib/appium_lib_core/ios/xcuitest/device.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/appium_lib_core/ios/xcuitest/device.rb b/lib/appium_lib_core/ios/xcuitest/device.rb index 124bb51f..09f87a35 100644 --- a/lib/appium_lib_core/ios/xcuitest/device.rb +++ b/lib/appium_lib_core/ios/xcuitest/device.rb @@ -114,7 +114,8 @@ module Device # # Get battery information. # - # @return [Hash] Return battery level and battery state. + # @return [Hash] Return battery level and battery state from the target real device. (Simulator has no battery.) + # https://developer.apple.com/documentation/uikit/uidevice/ 's `batteryLevel` and `batteryState`. # Battery level in range [0.0, 1.0], where 1.0 means 100% charge. -1 is returned # if the actual value cannot be retrieved from the system. # Battery state. The following symbols are possible