Skip to content

Commit

Permalink
rb: add HasNetworkConnection driver extension
Browse files Browse the repository at this point in the history
This is related to this issue:
https://code.google.com/p/selenium/issues/detail?id=7315

Signed-off-by: Andreas Tolfsen <[email protected]>
  • Loading branch information
jimvm authored and andreastt committed Mar 2, 2015
1 parent 7b1c21e commit e4b33f3
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/android/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def driver_extensions
DriverExtensions::HasInputDevices,
DriverExtensions::HasWebStorage,
DriverExtensions::HasLocation,
DriverExtensions::HasNetworkConnection,
DriverExtensions::HasTouchScreen
]
end
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
require 'selenium/webdriver/common/driver_extensions/has_session_id'
require 'selenium/webdriver/common/driver_extensions/has_touch_screen'
require 'selenium/webdriver/common/driver_extensions/has_remote_status'
require 'selenium/webdriver/common/driver_extensions/has_network_connection'
require 'selenium/webdriver/common/driver_extensions/uploads_files'
require 'selenium/webdriver/common/keys'
require 'selenium/webdriver/common/bridge_helper'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Selenium
module WebDriver
module DriverExtensions
module HasNetworkConnection
def network_connection_type
connection_value = @bridge.getNetworkConnection

# Convert connection value to type. In case the connection type is
# not recognized return the connection value.
case connection_value
when 1
:airplane_mode
when 2
:wifi
when 4
:data
when 6
:all
when 0
:none
else
connection_value
end
end

def network_connection_type=(connection_type)
# convert connection type to value
connection_value = case connection_type
when :airplane_mode
1
when :wifi
2
when :data
4
when :all
6
when :none
0
end

@bridge.setNetworkConnection connection_value
end
end
end
end
end
8 changes: 8 additions & 0 deletions rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,14 @@ def setLocation(lat, lon, alt)
execute :setLocation, {}, :location => loc
end

def getNetworkConnection
execute :getNetworkConnection
end

def setNetworkConnection(type)
execute :setNetworkConnection, {}, :type => type
end

#
# javascript execution
#
Expand Down
3 changes: 3 additions & 0 deletions rb/lib/selenium/webdriver/remote/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ class Selenium::WebDriver::Remote::Bridge
command :getAppCacheStatus, :get, "session/:session_id/application_cache/status"
command :clearAppCache, :delete, "session/:session_id/application_cache/clear"

command :getNetworkConnection, :get, "session/:session_id/network_connection"
command :setNetworkConnection, :post, "session/:session_id/network_connection"

command :getLocalStorageItem, :get, "session/:session_id/local_storage/key/:key"
command :removeLocalStorageItem, :delete, "session/:session_id/local_storage/key/:key"
command :getLocalStorageKeys, :get, "session/:session_id/local_storage"
Expand Down
16 changes: 16 additions & 0 deletions rb/spec/integration/selenium/webdriver/network_connection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require File.expand_path("../spec_helper", __FILE__)

module Selenium::WebDriver::DriverExtensions
describe HasNetworkConnection do
compliant_on :browser => nil do
it "can return the network connection type" do
expect(driver.network_connection_type).to eq :all
end

it "can set the network connection type" do
expect { driver.network_connection_type = :airplane_mode }.to
change { driver.network_connection_type }.from(:all).to(:airplane_mode)
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require File.expand_path("../../../spec_helper", __FILE__)

module Selenium
module WebDriver
module DriverExtensions
describe HasNetworkConnection do
class FakeDriver
include HasNetworkConnection
end

let(:driver) { FakeDriver.new }

describe "#network_connection" do
it "returns the correct connection type" do
@bridge.stub(:getNetworkConnection) { 1 }

expect(driver.network_connection_type).to eq :airplane_mode
end

it "returns an unknown connection value" do
@bridge.stub(:getNetworkConnection) { 5 }

expect(driver.network_connection_type).to eq 5
end
end

describe "#network_connection=" do
it "sends out the correct connection value" do
expect(@bridge).to receive(:setNetworkConnection).with(1)

driver.network_connection_type = :airplane_mode
end
end
end
end
end
end

0 comments on commit e4b33f3

Please sign in to comment.