Skip to content

Commit 703ec81

Browse files
authored
add toggles (#61)
* add toggles * add documentation
1 parent 1f93d58 commit 703ec81

File tree

6 files changed

+102
-4
lines changed

6 files changed

+102
-4
lines changed

lib/appium_lib_core/android/device/emulator.rb

+5
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ module Emulator
9292
#
9393
# @driver.set_power_ac :on
9494
#
95+
96+
####
97+
## self.emulator_commands
98+
####
99+
95100
def self.emulator_commands
96101
Appium::Core::Device.add_endpoint_method(:send_sms) do
97102
def send_sms(phone_number:, message:)

lib/appium_lib_core/common/command.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ module Commands
2424
get_display_density: [:get, 'session/:session_id/appium/device/display_density'.freeze],
2525
is_keyboard_shown: [:get, 'session/:session_id/appium/device/is_keyboard_shown'.freeze],
2626
get_network_connection: [:get, 'session/:session_id/network_connection'.freeze], # defined also in OSS
27-
get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze]
27+
get_performance_data_types: [:post, 'session/:session_id/appium/performanceData/types'.freeze],
28+
toggle_wifi: [:post, 'session/:session_id/appium/device/toggle_wifi'.freeze],
29+
toggle_data: [:post, 'session/:session_id/appium/device/toggle_data'.freeze],
30+
toggle_location_services: [:post, 'session/:session_id/appium/device/toggle_location_services'.freeze]
31+
2832
# iOS
2933
}.freeze
3034

lib/appium_lib_core/common/device.rb

+27
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,33 @@ module Device
138138
# @driver.device_time
139139
#
140140

141+
# @!method toggle_location_services
142+
# Switch the state of the location service
143+
# @return [String]
144+
#
145+
# @example
146+
#
147+
# @driver.toggle_location_services
148+
#
149+
150+
# @!method toggle_wifi
151+
# Switch the state of the wifi service
152+
# @return [String]
153+
#
154+
# @example
155+
#
156+
# @driver.toggle_wifi
157+
#
158+
159+
# @!method toggle_data
160+
# Switch the state of data service
161+
# @return [String]
162+
#
163+
# @example
164+
#
165+
# @driver.toggle_data
166+
#
167+
141168
####
142169
## With arguments
143170
####

test/unit/android/device_test.rb

+31
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,37 @@ def test_power_ac
659659

660660
assert_requested(:post, "#{SESSION}/appium/device/power_ac", times: 1)
661661
end
662+
663+
# toggles
664+
def test_toggle_wifi
665+
stub_request(:post, "#{SESSION}/appium/device/toggle_wifi")
666+
.with(body: '{}')
667+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
668+
669+
@driver.toggle_wifi
670+
671+
assert_requested(:post, "#{SESSION}/appium/device/toggle_wifi", times: 1)
672+
end
673+
674+
def test_toggle_data
675+
stub_request(:post, "#{SESSION}/appium/device/toggle_data")
676+
.with(body: '{}')
677+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
678+
679+
@driver.toggle_data
680+
681+
assert_requested(:post, "#{SESSION}/appium/device/toggle_data", times: 1)
682+
end
683+
684+
def test_toggle_location_services
685+
stub_request(:post, "#{SESSION}/appium/device/toggle_location_services")
686+
.with(body: '{}')
687+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
688+
689+
@driver.toggle_location_services
690+
691+
assert_requested(:post, "#{SESSION}/appium/device/toggle_location_services", times: 1)
692+
end
662693
end
663694
end
664695
end

test/unit/android/device_w3c_test.rb

+31
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,37 @@ def test_power_ac
649649

650650
assert_requested(:post, "#{SESSION}/appium/device/power_ac", times: 1)
651651
end
652+
653+
# toggles
654+
def test_toggle_wifi
655+
stub_request(:post, "#{SESSION}/appium/device/toggle_wifi")
656+
.with(body: '{}')
657+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
658+
659+
@driver.toggle_wifi
660+
661+
assert_requested(:post, "#{SESSION}/appium/device/toggle_wifi", times: 1)
662+
end
663+
664+
def test_toggle_data
665+
stub_request(:post, "#{SESSION}/appium/device/toggle_data")
666+
.with(body: '{}')
667+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
668+
669+
@driver.toggle_data
670+
671+
assert_requested(:post, "#{SESSION}/appium/device/toggle_data", times: 1)
672+
end
673+
674+
def test_toggle_location_services
675+
stub_request(:post, "#{SESSION}/appium/device/toggle_location_services")
676+
.with(body: '{}')
677+
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
678+
679+
@driver.toggle_location_services
680+
681+
assert_requested(:post, "#{SESSION}/appium/device/toggle_location_services", times: 1)
682+
end
652683
end
653684
end
654685
end

test/unit/script/commands_test.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@ def test_get_all_command_path
2222

2323
# depends on webdriver-version... (number of commands)
2424
def test_implemented_mjsonwp_commands
25-
assert_equal 139, @c.implemented_mjsonwp_commands.length
25+
assert_equal 142, @c.implemented_mjsonwp_commands.length
2626
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_mjsonwp_commands.first
2727

2828
# pick up an arbitrary command
2929
assert_equal %i(get post), @c.implemented_mjsonwp_commands['session/:session_id/alert_text']
3030
end
3131

3232
def test_implemented_w3c_commands
33-
assert_equal 110, @c.implemented_w3c_commands.length
33+
assert_equal 113, @c.implemented_w3c_commands.length
3434
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_w3c_commands.first
3535

3636
# pick up an arbitrary command
3737
assert_equal %i(get post), @c.implemented_w3c_commands['session/:session_id/alert/text']
3838
end
3939

4040
def test_implemented_core_commands
41-
assert_equal 53, @c.implemented_core_commands.length
41+
assert_equal 56, @c.implemented_core_commands.length
4242
assert_equal ['session/:session_id/contexts', [:get]], @c.implemented_core_commands.first
4343

4444
# pick up an arbitrary command

0 commit comments

Comments
 (0)