Skip to content

Commit 8fc56df

Browse files
committed
rb - implement option for setting Firefox binary locally
1 parent f667e4b commit 8fc56df

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

rb/lib/selenium/webdriver/firefox/bridge.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def initialize(opts = {})
3232

3333
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.firefox }
3434

35+
Binary.path = caps[:firefox_binary] if caps[:firefox_binary]
36+
3537
@launcher = create_launcher(port, profile)
3638

3739
unless opts.empty?

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ class W3CBridge < Remote::W3CBridge
2727
def initialize(opts = {})
2828
http_client = opts.delete(:http_client)
2929

30+
opts.delete(:marionette)
31+
caps = opts.delete(:desired_capabilities) { Remote::W3CCapabilities.firefox }
32+
3033
if opts.has_key?(:url)
3134
url = opts.delete(:url)
3235
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+
3341
@service = Service.default_service(*extract_service_args(opts))
3442

3543
if @service.instance_variable_get("@host") == "127.0.0.1"
@@ -41,7 +49,9 @@ def initialize(opts = {})
4149
url = @service.uri
4250
end
4351

44-
caps = create_capabilities(opts)
52+
unless opts.empty?
53+
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
54+
end
4555

4656
remote_opts = {
4757
:url => url,
@@ -71,16 +81,6 @@ def quit
7181

7282
private
7383

74-
def create_capabilities(opts)
75-
caps = opts.delete(:desired_capabilities) { Remote::W3CCapabilities.firefox }
76-
77-
unless opts.empty?
78-
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
79-
end
80-
81-
caps
82-
end
83-
8484
def extract_service_args(opts)
8585
args = []
8686

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ module Firefox
2626
compliant_on :driver => :firefox do
2727
describe Driver do
2828
describe ".new" do
29+
30+
it "should take a binary path as an argument" do
31+
pending unless ENV['MARIONETTE_PATH']
32+
33+
begin
34+
default_path = Firefox::Binary.path
35+
36+
driver1 = Selenium::WebDriver.for :firefox
37+
default_version = driver1.capabilities[:version]
38+
driver1.quit
39+
40+
caps = Remote::Capabilities.firefox(firefox_binary: ENV['MARIONETTE_PATH'])
41+
driver2 = Selenium::WebDriver.for :firefox, :desired_capabilities => caps
42+
43+
expect(driver2.capabilities[:version]).to_not be == default_version
44+
driver2.quit
45+
ensure
46+
Firefox::Binary.path = default_path
47+
end
48+
end
49+
2950
it "should take a Firefox::Profile instance as argument" do
3051
begin
3152
profile = Selenium::WebDriver::Firefox::Profile.new

0 commit comments

Comments
 (0)