Skip to content

Commit adecd64

Browse files
committed
rb - update w3c implementation for latest Marionette release
1 parent 5aed4ab commit adecd64

File tree

10 files changed

+116
-122
lines changed

10 files changed

+116
-122
lines changed

rb/lib/selenium/webdriver/common/options.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,9 @@ def add_cookie(opts = {})
5050
opts[:secure] ||= false
5151

5252
if obj = opts.delete(:expires)
53-
opts[:expiry] = seconds_from(obj)
53+
opts[:expiry] = seconds_from(obj).to_i
5454
end
5555

56-
5756
@bridge.addCookie opts
5857
end
5958

rb/lib/selenium/webdriver/firefox/w3c_bridge.rb

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,14 @@ module Firefox
2525
class W3CBridge < Remote::W3CBridge
2626

2727
def initialize(opts = {})
28-
http_client = opts.delete(:http_client)
28+
caps = opts[:desired_capabilities] ||= Remote::W3CCapabilities.firefox
29+
Binary.path = caps[:firefox_binary] if caps[:firefox_binary]
2930

30-
opts.delete(:marionette)
31-
caps = opts.delete(:desired_capabilities) { Remote::W3CCapabilities.firefox }
31+
@service = Service.default_service(*extract_service_args(opts))
32+
@service.start
33+
opts[:url] = @service.uri
3234

33-
if opts.has_key?(:url)
34-
url = opts.delete(:url)
35-
else
36-
Binary.path = caps[:firefox_binary] if caps[:firefox_binary]
37-
if Firefox::Binary.version < 43
38-
raise ArgumentError, "Firefox Version #{Firefox::Binary.version} does not support Marionette; Set firefox_binary in Capabilities to point to a supported binary"
39-
end
40-
41-
@service = Service.default_service(*extract_service_args(opts))
42-
43-
if @service.instance_variable_get("@host") == "127.0.0.1"
44-
@service.instance_variable_set("@host", 'localhost')
45-
end
46-
47-
@service.start
48-
49-
url = @service.uri
50-
end
51-
52-
unless opts.empty?
53-
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
54-
end
55-
56-
remote_opts = {
57-
:url => url,
58-
:desired_capabilities => caps
59-
}
60-
61-
remote_opts.merge!(:http_client => http_client) if http_client
62-
super(remote_opts)
35+
super
6336
end
6437

6538
def browser
@@ -83,13 +56,8 @@ def quit
8356
private
8457

8558
def extract_service_args(opts)
86-
args = []
87-
88-
if opts.has_key?(:service_log_path)
89-
args << "--log-path=#{opts.delete(:service_log_path)}"
90-
end
91-
92-
args
59+
service_log_path = opts.delete(:service_log_path)
60+
service_log_path ? ["--log-path=#{service_log_path}"] : []
9361
end
9462

9563
end # W3CBridge

rb/lib/selenium/webdriver/remote/w3c_bridge.rb

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def self.command(name, verb, url)
6262
#
6363

6464
def initialize(opts = {})
65-
if opts.key?(:desired_capabilities) && opts[:desired_capabilities][:browser_name] == 'MicrosoftEdge'
65+
if opts.fetch(:desired_capabilities, {})[:browser_name] == 'MicrosoftEdge'
6666
require_relative '../edge/legacy_support'
6767
extend Edge::LegacySupport
6868
end
@@ -73,35 +73,25 @@ def initialize(opts = {})
7373
desired_capabilities = opts.delete(:desired_capabilities) { W3CCapabilities.firefox }
7474
url = opts.delete(:url) { "http://#{Platform.localhost}:4444/wd/hub" }
7575

76-
if opts.delete(:marionette) && !desired_capabilities.is_a?(W3CCapabilities)
77-
caps = JSON.parse(desired_capabilities.to_json)
78-
desired_capabilities = W3CCapabilities.firefox(caps.merge(:marionette => true))
76+
desired_capabilities = W3CCapabilities.send(desired_capabilities) if desired_capabilities.is_a? Symbol
77+
78+
desired_capabilities[:marionette] = opts.delete(:marionette) unless opts[:marionette].nil?
79+
80+
if desired_capabilities[:marionette] && Firefox::Binary.version < 45
81+
raise Error::WebDriverError, "Marionette is not supported in Firefox Version #{Firefox::Binary.version}"
7982
end
8083

8184
unless opts.empty?
8285
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
8386
end
8487

85-
if desired_capabilities.kind_of?(Symbol)
86-
unless W3CCapabilities.respond_to?(desired_capabilities)
87-
raise Error::WebDriverError, "invalid desired capability: #{desired_capabilities.inspect}"
88-
end
89-
90-
desired_capabilities = W3CCapabilities.send(desired_capabilities)
91-
end
92-
9388
uri = url.kind_of?(URI) ? url : URI.parse(url)
9489
uri.path += "/" unless uri.path =~ /\/$/
9590

9691
http_client.server_url = uri
9792

9893
@http = http_client
9994
@capabilities = create_session(desired_capabilities)
100-
101-
if @capabilities[:browser_name] == 'firefox' && @capabilities[:browser_version].to_i < 43
102-
raise ArgumentError, "Server configuration does not support Marionette; start server with flag to Marionette binary -Dwebdriver.firefox.bin=/path/to/bin"
103-
end
104-
10595
@file_detector = nil
10696
end
10797

rb/lib/selenium/webdriver/remote/w3c_capabilities.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,21 +87,25 @@ def w3c?(opts = {})
8787
def json_create(data)
8888
data = data.dup
8989

90+
# Convert due to Remote Driver implementation
91+
data["browserVersion"] = data.delete("version") if data["version"]
92+
data["platformName"] = data.delete("platform") if data["platform"]
93+
9094
caps = new
91-
caps.browser_name = data.delete("browserName")
92-
caps.browser_version = data.delete("browserVersion")
93-
caps.platform_name = data.delete("platformName")
94-
caps.platform_version = data.delete("platformVersion")
95-
caps.accept_ssl_certs = data.delete("acceptSslCerts")
96-
caps.takes_screenshot = data.delete("takesScreenshot")
97-
caps.takes_element_screenshot = data.delete("takesElementScreenshot")
98-
caps.page_load_strategy = data.delete("pageLoadStrategy")
99-
caps.proxy = Proxy.json_create(data['proxy']) if data.has_key?('proxy')
95+
caps.browser_name = data.delete("browserName") if data["browserName"]
96+
caps.browser_version = data.delete("browserVersion") if data["browserVersion"]
97+
caps.platform_name = data.delete("platformName") if data["platformName"]
98+
caps.platform_version = data.delete("platformVersion") if data["platformVersion"]
99+
caps.accept_ssl_certs = data.delete("acceptSslCerts") if data["acceptSslCerts"]
100+
caps.takes_screenshot = data.delete("takesScreenshot") if data["takesScreenshot"]
101+
caps.takes_element_screenshot = data.delete("takesElementScreenshot") if data["takesElementScreenshot"]
102+
caps.page_load_strategy = data.delete("pageLoadStrategy") if data["pageloadStrategy"]
103+
caps.proxy = Proxy.json_create(data['proxy']) if data['proxy']
100104

101105
# Remote Server Specific
102106
caps[:remote_session_id] = data.delete('webdriver.remote.sessionid')
103107

104-
# obsolete capabilities returned by Remote Server
108+
# Obsolete capabilities returned by Remote Server
105109
data.delete("javascriptEnabled")
106110
data.delete('cssSelectorsEnabled')
107111

rb/spec/integration/selenium/webdriver/driver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@
282282
end
283283

284284
# Edge BUG - https://connect.microsoft.com/IE/feedback/details/1849991/
285-
not_compliant_on({:browser => [:edge, :marionette, :edge]},
285+
not_compliant_on({:browser => [:edge, :marionette]},
286286
{:driver => :remote, :browser => :phantomjs}) do
287287
it "times out if the callback is not invoked" do
288288
expect {

rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ module Firefox
2727
describe Driver do
2828
describe ".new" do
2929

30-
it "should take a binary path as an argument" do
31-
pending unless ENV['MARIONETTE_PATH']
30+
it "takes a binary path as an argument" do
31+
pending "Set ENV['ALTERNATE_FIREFOX_PATH'] to test this" unless ENV['ALTERNATE_FIREFOX_PATH']
3232

3333
begin
3434
default_path = Firefox::Binary.path
@@ -37,7 +37,7 @@ module Firefox
3737
default_version = driver1.capabilities[:version]
3838
driver1.quit
3939

40-
caps = Remote::Capabilities.firefox(firefox_binary: ENV['MARIONETTE_PATH'])
40+
caps = Remote::Capabilities.firefox(firefox_binary: ENV['ALTERNATE_FIREFOX_PATH'])
4141
driver2 = Selenium::WebDriver.for :firefox, :desired_capabilities => caps
4242

4343
expect(driver2.capabilities[:version]).to_not be == default_version
@@ -47,7 +47,7 @@ module Firefox
4747
end
4848
end
4949

50-
it "should take a Firefox::Profile instance as argument" do
50+
it "takes a Firefox::Profile instance as argument" do
5151
begin
5252
profile = Selenium::WebDriver::Firefox::Profile.new
5353
driver = Selenium::WebDriver.for :firefox, :profile => profile
@@ -60,8 +60,8 @@ module Firefox
6060
end
6161

6262
it_behaves_like "driver that can be started concurrently", :firefox
63-
end
6463

64+
end # Driver
6565
end
6666

6767
end # Firefox

rb/spec/integration/selenium/webdriver/firefox/marionette_spec.rb

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,27 @@ module WebDriver
2727
@opt = GlobalTestEnv.remote_server? ? {:url => GlobalTestEnv.remote_server.webdriver_url} : {}
2828
end
2929

30+
compliant_on :driver => :marionette do
31+
it "takes a binary path as an argument" do
32+
pending "Set ENV['ALTERNATE_FIREFOX_PATH'] to test this" unless ENV['ALTERNATE_FIREFOX_PATH']
33+
pending "Set ENV['MARIONETTE_PATH'] to test this" unless ENV['MARIONETTE_PATH']
34+
35+
begin
36+
caps = Remote::Capabilities.firefox(:firefox_binary => ENV['MARIONETTE_PATH'])
37+
driver1 = Selenium::WebDriver.for :firefox, :desired_capabilities => caps, :marionette => true
38+
39+
default_version = driver1.capabilities.version
40+
driver1.quit
41+
42+
caps = Remote::Capabilities.firefox(:firefox_binary => ENV['ALTERNATE_FIREFOX_PATH'])
43+
driver2 = Selenium::WebDriver.for :firefox, :desired_capabilities => caps, :marionette => true
44+
45+
expect(driver2.capabilities.version).to_not be == default_version
46+
driver2.quit
47+
end
48+
end
49+
end
50+
3051
context "when designated firefox binary includes Marionette" do
3152
before do
3253
unless ENV['MARIONETTE_PATH']
@@ -84,25 +105,32 @@ module WebDriver
84105
end
85106

86107
compliant_on :browser => :firefox do
87-
# TODO - Adjust specs when default Firefox version includes Marionette
88-
# TODO - File bug for Unhandled error for remote / firefox
108+
# These pass in isolation, but can not run in suite due to https://github.com/SeleniumHQ/selenium/issues/1150
89109
not_compliant_on :driver => :remote do
90110
context "when designated firefox binary does not include Marionette" do
91-
let(:message) { /does not support Marionette/ }
111+
let(:message) { /Marionette is not supported in Firefox Version \d\d/ }
112+
113+
before do
114+
unless ENV['PRE_MARIONETTE_PATH']
115+
pending "Set ENV['PRE_MARIONETTE_PATH'] to test features on firefox versions without marionette"
116+
end
117+
end
92118

93119
it "Raises Wires Exception when setting marionette option in capabilities" do
94-
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:marionette => true)
120+
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:marionette => true,
121+
:firefox_binary => ENV['PRE_MARIONETTE_PATH'])
95122
@opt.merge!(:desired_capabilities => caps)
96-
expect { Selenium::WebDriver.for GlobalTestEnv.driver, @opt }.to raise_exception ArgumentError, message
123+
expect { Selenium::WebDriver.for GlobalTestEnv.driver, @opt }.to raise_exception Error::WebDriverError, message
97124
end
98125

99126
it "Raises Wires Exception when setting marionette option in driver initialization" do
100-
@opt.merge!(:marionette => true)
101-
expect{ Selenium::WebDriver.for GlobalTestEnv.driver, @opt}.to raise_exception ArgumentError, message
127+
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_binary => ENV['PRE_MARIONETTE_PATH'])
128+
@opt.merge!(:marionette => true, :desired_capabilities => caps)
129+
expect{ Selenium::WebDriver.for GlobalTestEnv.driver, @opt}.to raise_exception Error::WebDriverError, message
102130
end
103131
end
104132
end
105133
end
106-
end
134+
end # Firefox
107135
end # WebDriver
108136
end # Selenium

rb/spec/integration/selenium/webdriver/options_spec.rb

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -64,55 +64,53 @@ module WebDriver
6464
end
6565
end
6666

67-
not_compliant_on :browser => :marionette do
68-
describe "cookie management" do
67+
describe "cookie management" do
6968

70-
it "should get all" do
71-
driver.navigate.to url_for("xhtmlTest.html")
72-
driver.manage.add_cookie :name => "foo", :value => "bar"
69+
it "should get all" do
70+
driver.navigate.to url_for("xhtmlTest.html")
71+
driver.manage.add_cookie :name => "foo", :value => "bar"
7372

74-
cookies = driver.manage.all_cookies
73+
cookies = driver.manage.all_cookies
7574

76-
expect(cookies.size).to eq(1)
77-
expect(cookies.first[:name]).to eq("foo")
78-
expect(cookies.first[:value]).to eq("bar")
79-
end
75+
expect(cookies.size).to eq(1)
76+
expect(cookies.first[:name]).to eq("foo")
77+
expect(cookies.first[:value]).to eq("bar")
78+
end
8079

81-
# Edge BUG - https://connect.microsoft.com/IE/feedbackdetail/view/1864122
82-
not_compliant_on :browser => :edge do
83-
it "should delete one" do
84-
driver.navigate.to url_for("xhtmlTest.html")
85-
driver.manage.add_cookie :name => "foo", :value => "bar"
80+
# Edge BUG - https://connect.microsoft.com/IE/feedbackdetail/view/1864122
81+
not_compliant_on :browser => :edge do
82+
it "should delete one" do
83+
driver.navigate.to url_for("xhtmlTest.html")
84+
driver.manage.add_cookie :name => "foo", :value => "bar"
8685

87-
driver.manage.delete_cookie("foo")
88-
end
86+
driver.manage.delete_cookie("foo")
8987
end
88+
end
9089

91-
# This is not a w3c supported spec
92-
not_compliant_on :browser => :edge do
93-
it "should delete all" do
94-
driver.navigate.to url_for("xhtmlTest.html")
90+
# This is not a w3c supported spec
91+
not_compliant_on :browser => :edge do
92+
it "should delete all" do
93+
driver.navigate.to url_for("xhtmlTest.html")
9594

96-
driver.manage.add_cookie :name => "foo", :value => "bar"
97-
driver.manage.delete_all_cookies
98-
expect(driver.manage.all_cookies).to be_empty
99-
end
95+
driver.manage.add_cookie :name => "foo", :value => "bar"
96+
driver.manage.delete_all_cookies
97+
expect(driver.manage.all_cookies).to be_empty
10098
end
99+
end
101100

102-
# Marionette BUG - Failed to convert expiry to Date
103-
not_compliant_on :browser => [:android, :iphone, :safari, :marionette] do
104-
it "should use DateTime for expires" do
105-
driver.navigate.to url_for("xhtmlTest.html")
101+
# Marionette BUG - Failed to convert expiry to Date
102+
not_compliant_on :browser => [:android, :iphone, :safari, :marionette] do
103+
it "should use DateTime for expires" do
104+
driver.navigate.to url_for("xhtmlTest.html")
106105

107-
expected = DateTime.new(2039)
108-
driver.manage.add_cookie :name => "foo",
109-
:value => "bar",
110-
:expires => expected
106+
expected = DateTime.new(2039)
107+
driver.manage.add_cookie :name => "foo",
108+
:value => "bar",
109+
:expires => expected
111110

112-
actual = driver.manage.cookie_named("foo")[:expires]
113-
expect(actual).to be_kind_of(DateTime)
114-
expect(actual).to eq(expected)
115-
end
111+
actual = driver.manage.cookie_named("foo")[:expires]
112+
expect(actual).to be_kind_of(DateTime)
113+
expect(actual).to eq(expected)
116114
end
117115
end
118116
end

rb/spec/integration/selenium/webdriver/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Object
3636
RSpec.configure do |c|
3737
c.include(WebDriver::SpecSupport::Helpers)
3838
c.before(:suite) do
39-
Selenium::WebDriver::Firefox::Binary.path = ENV['MARIONETTE_PATH'] if GlobalTestEnv.browser == :marionette
39+
Selenium::WebDriver::Firefox::Binary.path = ENV['MARIONETTE_PATH'] if GlobalTestEnv.browser == :marionette && ENV['MARIONETTE_PATH']
4040
if GlobalTestEnv.driver == :remote
4141
server = GlobalTestEnv.remote_server
4242
if GlobalTestEnv.browser == :marionette

0 commit comments

Comments
 (0)