diff --git a/lib/appium_lib_core/android/device/emulator.rb b/lib/appium_lib_core/android/device/emulator.rb index ebc4c115..ef0010f3 100644 --- a/lib/appium_lib_core/android/device/emulator.rb +++ b/lib/appium_lib_core/android/device/emulator.rb @@ -92,6 +92,11 @@ module Emulator # # @driver.set_power_ac :on # + + #### + ## self.emulator_commands + #### + def self.emulator_commands Appium::Core::Device.add_endpoint_method(:send_sms) do def send_sms(phone_number:, message:) diff --git a/lib/appium_lib_core/common/command.rb b/lib/appium_lib_core/common/command.rb index 4bf6c909..5ab62275 100644 --- a/lib/appium_lib_core/common/command.rb +++ b/lib/appium_lib_core/common/command.rb @@ -24,7 +24,11 @@ module Commands get_display_density: [:get, 'session/:session_id/appium/device/display_density'.freeze], is_keyboard_shown: [:get, 'session/:session_id/appium/device/is_keyboard_shown'.freeze], get_network_connection: [:get, 'session/:session_id/network_connection'.freeze], # defined also in OSS - get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze] + get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze], + toggle_wifi: [:post, 'session/:session_id/appium/device/toggle_wifi'.freeze], + toggle_data: [:post, 'session/:session_id/appium/device/toggle_data'.freeze], + toggle_location_services: [:post, 'session/:session_id/appium/device/toggle_location_services'.freeze] + # iOS }.freeze diff --git a/lib/appium_lib_core/common/device.rb b/lib/appium_lib_core/common/device.rb index c09601a1..def86f50 100644 --- a/lib/appium_lib_core/common/device.rb +++ b/lib/appium_lib_core/common/device.rb @@ -138,6 +138,33 @@ module Device # @driver.device_time # + # @!method toggle_location_services + # Switch the state of the location service + # @return [String] + # + # @example + # + # @driver.toggle_location_services + # + + # @!method toggle_wifi + # Switch the state of the wifi service + # @return [String] + # + # @example + # + # @driver.toggle_wifi + # + + # @!method toggle_data + # Switch the state of data service + # @return [String] + # + # @example + # + # @driver.toggle_data + # + #### ## With arguments #### diff --git a/test/unit/android/device_test.rb b/test/unit/android/device_test.rb index 1d275dd4..12cb107c 100644 --- a/test/unit/android/device_test.rb +++ b/test/unit/android/device_test.rb @@ -659,6 +659,37 @@ def test_power_ac 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) + end + + def test_toggle_location_services + stub_request(:post, "#{SESSION}/appium/device/toggle_location_services") + .with(body: '{}') + .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) + end end end end diff --git a/test/unit/android/device_w3c_test.rb b/test/unit/android/device_w3c_test.rb index 4084bdb4..abcd28f5 100644 --- a/test/unit/android/device_w3c_test.rb +++ b/test/unit/android/device_w3c_test.rb @@ -649,6 +649,37 @@ def test_power_ac 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) + end + + def test_toggle_location_services + stub_request(:post, "#{SESSION}/appium/device/toggle_location_services") + .with(body: '{}') + .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) + end end end end diff --git a/test/unit/script/commands_test.rb b/test/unit/script/commands_test.rb index 3b42b167..f1cfa2bc 100644 --- a/test/unit/script/commands_test.rb +++ b/test/unit/script/commands_test.rb @@ -22,7 +22,7 @@ def test_get_all_command_path # depends on webdriver-version... (number of commands) def test_implemented_mjsonwp_commands - assert_equal 139, @c.implemented_mjsonwp_commands.length + assert_equal 142, @c.implemented_mjsonwp_commands.length assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_mjsonwp_commands.first # pick up an arbitrary command @@ -30,7 +30,7 @@ def test_implemented_mjsonwp_commands end def test_implemented_w3c_commands - assert_equal 110, @c.implemented_w3c_commands.length + assert_equal 113, @c.implemented_w3c_commands.length assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_w3c_commands.first # pick up an arbitrary command @@ -38,7 +38,7 @@ def test_implemented_w3c_commands end def test_implemented_core_commands - assert_equal 53, @c.implemented_core_commands.length + assert_equal 56, @c.implemented_core_commands.length assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_core_commands.first # pick up an arbitrary command