Skip to content

Commit a282e16

Browse files
committed
rb - fix remote server implementation for Marionette
1 parent 6aff8c7 commit a282e16

File tree

13 files changed

+328
-287
lines changed

13 files changed

+328
-287
lines changed

rb/build.desc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,8 @@ ruby_test(name = "remote-marionette",
307307
include = ["rb/spec/integration", "build/rb/lib"],
308308
deps = [
309309
"//java/server/test/org/openqa/selenium:server-with-tests:uber",
310-
":remote"
310+
":remote",
311+
":firefox"
311312
]
312313
)
313314

rb/lib/selenium/webdriver/remote/capabilities.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def edge(opts = {})
8888
end
8989

9090
def firefox(opts = {})
91-
return W3CCapabilities.firefox(opts) if opts.delete(:marionette)
91+
return W3CCapabilities.firefox(opts) if opts[:marionette]
9292

9393
new({
9494
:browser_name => "firefox",

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20+
require 'json'
21+
2022
module Selenium
2123
module WebDriver
2224
module Remote
@@ -66,6 +68,11 @@ def initialize(opts = {})
6668
desired_capabilities = opts.delete(:desired_capabilities) { W3CCapabilities.firefox }
6769
url = opts.delete(:url) { "http://#{Platform.localhost}:4444/wd/hub" }
6870

71+
if opts.delete(:marionette) && !desired_capabilities.is_a?(W3CCapabilities)
72+
caps = JSON.parse(desired_capabilities.to_json)
73+
desired_capabilities = W3CCapabilities.firefox(caps.merge(:marionette => true))
74+
end
75+
6976
unless opts.empty?
7077
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
7178
end
@@ -86,6 +93,10 @@ def initialize(opts = {})
8693
@http = http_client
8794
@capabilities = create_session(desired_capabilities)
8895

96+
if @capabilities[:browser_name] == 'firefox' && @capabilities[:browser_version].to_i < 43
97+
raise ArgumentError, "Server configuration does not support Marionette; start server with flag to Marionette binary -Dwebdriver.firefox.bin=/path/to/bin"
98+
end
99+
89100
@file_detector = nil
90101
end
91102

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,19 @@ def edge(opts = {})
6464
end
6565

6666
def firefox(opts = {})
67+
opts[:browser_version] = opts.delete :version
68+
opts[:platform_name] = opts.delete :platform
69+
6770
new({
68-
:browser_name => "firefox"
71+
:browser_name => "firefox",
72+
:marionette => true
6973
}.merge(opts))
7074
end
7175

7276
alias_method :ff, :firefox
7377

7478
def w3c?(opts = {})
75-
intended = opts[:desired_capabilities].is_a?(W3CCapabilities) || !!opts.delete(:marionette)
76-
if intended && Firefox::Binary.version < 43
77-
raise ArgumentError, "Firefox Version #{Firefox::Binary.version} does not support Marionette; Set Selenium::WebDriver::Firefox::Binary.path to point to a supported binary"
78-
elsif intended
79-
true
80-
else
81-
false
82-
end
79+
opts[:desired_capabilities].is_a?(W3CCapabilities) || opts[:marionette]
8380
end
8481

8582
#
@@ -92,14 +89,29 @@ def json_create(data)
9289
caps = new
9390
caps.browser_name = data.delete("browserName")
9491
caps.browser_version = data.delete("browserVersion")
95-
caps.platform_name = data.delete("platformName").downcase.to_sym if data.has_key?('platform')
92+
caps.platform_name = data.delete("platformName")
9693
caps.platform_version = data.delete("platformVersion")
9794
caps.accept_ssl_certs = data.delete("acceptSslCerts")
98-
caps.takes_screenshot = data.delete("takesScreenshot ")
95+
caps.takes_screenshot = data.delete("takesScreenshot")
9996
caps.takes_element_screenshot = data.delete("takesElementScreenshot")
10097
caps.page_load_strategy = data.delete("pageLoadStrategy")
10198
caps.proxy = Proxy.json_create(data['proxy']) if data.has_key?('proxy')
10299

100+
# Remote Server Specific
101+
caps[:remote_session_id] = data.delete('webdriver.remote.sessionid')
102+
103+
# obsolete capabilities returned by Remote Server
104+
data.delete("javascriptEnabled")
105+
data.delete('cssSelectorsEnabled')
106+
107+
# Marionette Specific
108+
caps[:specification_level] = data.delete("specificaionLevel")
109+
caps[:xul_app_id] = data.delete("XULappId")
110+
caps[:raise_accessibility_exceptions] = data.delete('raisesAccessibilityExceptions')
111+
caps[:rotatable] = data.delete('rotatable')
112+
caps[:app_build_id] = data.delete('appBuildId')
113+
caps[:device] = data.delete('device')
114+
103115
# any remaining pairs will be added as is, with no conversion
104116
caps.merge!(data)
105117

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
end
2727

2828
# Marionette BUG - AutomatedTester: "I need to add pagesource back and add it to the spec"
29-
not_compliant_on :driver => :marionette do
29+
not_compliant_on :browser => :marionette do
3030
it "should get the page source" do
3131
driver.navigate.to url_for("xhtmlTest.html")
3232
expect(driver.page_source).to match(%r[<title>XHTML Test Page</title>]i)

rb/spec/integration/selenium/webdriver/element_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
end
3737

3838
# Marionette BUG - AutomatedTester: "known bug with execute script"
39-
not_compliant_on :driver => :marionette do
39+
not_compliant_on :browser => :marionette do
4040
it "should submit" do
4141
driver.navigate.to url_for("formPage.html")
4242
wait(5).until {driver.find_elements(:id, "submitButton").size > 0}
@@ -142,7 +142,7 @@
142142
end
143143

144144
# Location not currently supported in Spec, but should be?
145-
not_compliant_on :driver => :marionette do
145+
not_compliant_on :browser => :marionette do
146146
it "should get location" do
147147
driver.navigate.to url_for("xhtmlTest.html")
148148
loc = driver.find_element(:class, "header").location
@@ -165,7 +165,7 @@
165165
# Marionette BUG:
166166
# GET /session/f7082a32-e685-2843-ad2c-5bb6f376dac5/element/b6ff4468-ed6f-7c44-be4b-ca5a3ea8bf26/size
167167
# did not match a known command"
168-
not_compliant_on :driver => :marionette do
168+
not_compliant_on :browser => :marionette do
169169
it "should get size" do
170170
driver.navigate.to url_for("xhtmlTest.html")
171171
size = driver.find_element(:class, "header").size

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

Lines changed: 58 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,69 +23,83 @@ module Selenium
2323
module WebDriver
2424

2525
describe Firefox do
26-
compliant_on :browser => :marionette do
27-
context "when designated firefox binary includes Marionette" do
28-
before(:each) do
29-
Selenium::WebDriver::Firefox::Binary.path = ENV['MARIONETTE_PATH']
30-
end
31-
32-
it "Uses Wires when initialized with W3C desired_capabilities" do
33-
caps = Selenium::WebDriver::Remote::W3CCapabilities.firefox
34-
expect do
35-
@driver = Selenium::WebDriver.for :firefox, :desired_capabilities => caps
36-
end.to_not raise_exception
37-
@driver.quit
38-
end
26+
before(:each) do
27+
@opt = GlobalTestEnv.remote_server? ? {:url => GlobalTestEnv.remote_server.webdriver_url} : {}
28+
end
3929

40-
it "Uses Wires when initialized with non W3C desired_capabilities using marionette option" do
41-
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:marionette => true)
42-
expect do
43-
@driver = Selenium::WebDriver.for :firefox, :desired_capabilities => caps
44-
end.to_not raise_exception
45-
@driver.quit
30+
context "when designated firefox binary includes Marionette" do
31+
before(:each) do
32+
unless ENV['MARIONETTE_PATH']
33+
pending "Set ENV['MARIONETTE_PATH'] to test Marionette enabled Firefox installations"
4634
end
35+
end
4736

48-
it "Uses Wires when initialized with marionette option" do
49-
@driver = Selenium::WebDriver.for :firefox, {marionette: true}
50-
expect(@driver.instance_variable_get('@bridge').instance_variable_get('@launcher')).to be_nil
51-
@driver.quit
37+
compliant_on :browser => :marionette do
38+
# This passes in isolation, but can not run in suite due to combination of
39+
# https://bugzilla.mozilla.org/show_bug.cgi?id=1228107 & https://github.com/SeleniumHQ/selenium/issues/1150
40+
not_compliant_on :driver => :remote do
41+
it "Uses Wires when setting marionette option in capabilities" do
42+
cap_opts = {:marionette => true}
43+
cap_opts.merge!(:firefox_binary => ENV['MARIONETTE_PATH']) unless GlobalTestEnv.driver == :remote
44+
caps = Selenium::WebDriver::Remote::Capabilities.firefox cap_opts
45+
@opt.merge!(:desired_capabilities => caps)
46+
expect {@driver = Selenium::WebDriver.for GlobalTestEnv.driver, @opt}.to_not raise_exception
47+
@driver.quit
48+
end
5249
end
50+
end
5351

54-
not_compliant_on :browser => :marionette do
55-
it "Does not use wires by default" do
56-
unless ENV['MARIONETTE_PATH']
57-
pending "Set ENV['MARIONETTE_PATH'] to test Marionette enabled Firefox installations"
58-
end
52+
compliant_on :browser => :marionette do
53+
# This passes in isolation, but can not run in suite due to combination of
54+
# https://bugzilla.mozilla.org/show_bug.cgi?id=1228107 & https://github.com/SeleniumHQ/selenium/issues/1150
55+
not_compliant_on :driver => :remote do
56+
it "Uses Wires when setting marionette option in driver initialization" do
57+
cap_opts = GlobalTestEnv.driver == :remote ? {} : {:firefox_binary => ENV['MARIONETTE_PATH']}
58+
caps = Selenium::WebDriver::Remote::Capabilities.firefox cap_opts
59+
@opt.merge!(:marionette => true, :desired_capabilities => caps)
60+
@driver = Selenium::WebDriver.for GlobalTestEnv.driver, @opt
5961

60-
Selenium::WebDriver::Firefox::Binary.path = ENV['MARIONETTE_PATH']
61-
@driver = Selenium::WebDriver.for :firefox
62-
expect(@driver.instance_variable_get('@bridge').instance_variable_get('@launcher')).to_not be_nil
62+
expect(@driver.capabilities[:takes_element_screenshot]).to_not be_nil
6363
@driver.quit
6464
end
6565
end
66+
end
67+
68+
# test with firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=1228121
69+
compliant_on :browser => :firefox do
70+
it "Does not use wires when marionette option is not set" do
71+
@driver = Selenium::WebDriver.for GlobalTestEnv.driver, @opt
72+
73+
expect(@driver.capabilities[:takes_element_screenshot]).to be_nil
74+
@driver.quit
75+
end
76+
end
6677

78+
compliant_on :browser => :marionette do
79+
# https://bugzilla.mozilla.org/show_bug.cgi?id=1228107
6780
not_compliant_on :browser => :marionette do
6881
it_behaves_like "driver that can be started concurrently", :marionette
6982
end
7083
end
7184
end
7285

7386
compliant_on :browser => :firefox do
74-
context "when designated firefox binary does not include Marionette" do
75-
let(:message) { /Firefox Version \d\d does not support Marionette/ }
87+
# TODO - Adjust specs when default Firefox version includes Marionette
88+
# TODO - File bug for Unhandled error for remote / firefox
89+
not_compliant_on :driver => :remote do
90+
context "when designated firefox binary does not include Marionette" do
91+
let(:message) { /does not support Marionette/ }
7692

77-
it "Raises Wires Exception when initialized with :desired_capabilities" do
78-
caps = Selenium::WebDriver::Remote::W3CCapabilities.firefox
79-
opt = {:desired_capabilities => caps}
80-
expect { Selenium::WebDriver.for :firefox, opt }.to raise_exception ArgumentError, message
81-
end
82-
83-
it "Raises Wires Exception when initialized with marionette option" do
84-
expect{Selenium::WebDriver.for :firefox, {marionette: true}}.to raise_exception ArgumentError, message
85-
end
93+
it "Raises Wires Exception when setting marionette option in capabilities" do
94+
caps = Selenium::WebDriver::Remote::Capabilities.firefox(:marionette => true)
95+
@opt.merge!(:desired_capabilities => caps)
96+
expect { Selenium::WebDriver.for GlobalTestEnv.driver, @opt }.to raise_exception ArgumentError, message
97+
end
8698

87-
it "Raises Wires Exception when initialized with marionette option" do
88-
expect{Selenium::WebDriver.for :firefox, {marionette: true}}.to raise_exception ArgumentError, message
99+
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
102+
end
89103
end
90104
end
91105
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ module WebDriver
6666
end
6767
end
6868

69-
not_compliant_on({:browser => :ie}) do
69+
not_compliant_on({:browser => [:ie, :marionette]}) do
7070
describe "cookie management" do
7171
it "should get all" do
7272
driver.navigate.to url_for("xhtmlTest.html")

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@ module Remote
2929
expect(driver.session_id).to be_kind_of(String)
3030
end
3131

32-
it "should expose remote status" do
33-
expect(driver).to be_kind_of(DriverExtensions::HasRemoteStatus)
34-
expect(driver.remote_status).to be_kind_of(Hash)
32+
# status is not w3c compliant
33+
not_compliant_on :browser => :marionette do
34+
it "should expose remote status" do
35+
expect(driver).to be_kind_of(DriverExtensions::HasRemoteStatus)
36+
expect(driver.remote_status).to be_kind_of(Hash)
37+
end
3538
end
3639
end
3740
end

rb/spec/integration/selenium/webdriver/remote/element_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module WebDriver
3232
driver.file_detector = nil
3333
end
3434

35-
not_compliant_on :browser => [:phantomjs, :safari] do
35+
not_compliant_on :browser => [:phantomjs, :safari, :marionette] do
3636
it "uses the file detector" do
3737
driver.navigate.to url_for("upload.html")
3838

0 commit comments

Comments
 (0)