Skip to content

add toggles #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/appium_lib_core/android/device/emulator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:)
Expand Down
6 changes: 5 additions & 1 deletion lib/appium_lib_core/common/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions lib/appium_lib_core/common/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
####
Expand Down
31 changes: 31 additions & 0 deletions test/unit/android/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions test/unit/android/device_w3c_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/unit/script/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ 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
assert_equal %i(get post), @c.implemented_mjsonwp_commands['session/:session_id/alert_text']
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
assert_equal %i(get post), @c.implemented_w3c_commands['session/:session_id/alert/text']
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
Expand Down