-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rb: add HasNetworkConnection driver extension
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
Showing
7 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
rb/lib/selenium/webdriver/common/driver_extensions/has_network_connection.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
rb/spec/integration/selenium/webdriver/network_connection_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
37 changes: 37 additions & 0 deletions
37
rb/spec/unit/selenium/webdriver/common/driver_extensions/has_network_connection_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |