Skip to content

Commit

Permalink
Lookup and pass Firefox binary location to GeckoDriver
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed May 21, 2019
1 parent 022771d commit 15f966d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
33 changes: 23 additions & 10 deletions rb/lib/selenium/webdriver/common/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,38 @@ class Service
class << self
attr_reader :driver_path

def chrome(*args)
Chrome::Service.new(*args)
def chrome(**opts)
Chrome::Service.new(**opts)
end

def firefox(*args)
Firefox::Service.new(*args)
def firefox(**opts)
binary_path = Firefox::Binary.path
args = opts.delete(:args)
case args
when Hash
args[:binary] ||= binary_path
opts[:args] = args
when Array
opts[:args] = ["--binary=#{binary_path}"]
opts[:args] += args
else
opts[:args] = ["--binary=#{binary_path}"]
end

Firefox::Service.new(**opts)
end

def ie(*args)
IE::Service.new(*args)
def ie(**opts)
IE::Service.new(**opts)
end
alias_method :internet_explorer, :ie

def edge(*args)
Edge::Service.new(*args)
def edge(**opts)
Edge::Service.new(**opts)
end

def safari(*args)
Safari::Service.new(*args)
def safari(**opts)
Safari::Service.new(**opts)
end

def driver_path=(path)
Expand Down
14 changes: 8 additions & 6 deletions rb/spec/unit/selenium/webdriver/firefox/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module WebDriver

before do
allow(Platform).to receive(:assert_executable).and_return(true)
allow(Firefox::Binary).to receive(:path).and_return('/foo/bar')
end

describe '#new' do
Expand Down Expand Up @@ -84,20 +85,20 @@ module WebDriver
expect(service.executable_path).to eq path
end

it 'does not create args by default' do
it 'provides binary path by default' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = Service.firefox

expect(service.instance_variable_get('@extra_args')).to be_empty
expect(service.instance_variable_get('@extra_args')).to eq(['--binary=/foo/bar'])
end

it 'uses provided args' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = Service.firefox(args: ['--foo', '--bar'])

expect(service.instance_variable_get('@extra_args')).to eq ['--foo', '--bar']
expect(service.instance_variable_get('@extra_args')).to include('--foo', '--bar')
end

# This is deprecated behavior
Expand All @@ -107,7 +108,7 @@ module WebDriver
service = Service.firefox(args: {log: '/path/to/log',
marionette_port: 4})

expect(service.instance_variable_get('@extra_args')).to eq ['--log=/path/to/log', '--marionette-port=4']
expect(service.instance_variable_get('@extra_args')).to include('--log=/path/to/log', '--marionette-port=4')
end
end
end
Expand All @@ -119,6 +120,7 @@ module Firefox

before do
allow(Remote::Bridge).to receive(:new).and_return(bridge)
allow(Firefox::Binary).to receive(:path).and_return('/foo/bar')
end

it 'is not created when :url is provided' do
Expand All @@ -138,7 +140,7 @@ module Firefox

expect(Service).to receive(:new).with(path: driver_path,
port: nil,
args: nil).and_return(service)
args: ['--binary=/foo/bar']).and_return(service)

expect {
described_class.new(driver_path: driver_path)
Expand All @@ -150,7 +152,7 @@ module Firefox

expect(Service).to receive(:new).with(path: nil,
port: driver_port,
args: nil).and_return(service)
args: ['--binary=/foo/bar']).and_return(service)

expect {
described_class.new(port: driver_port)
Expand Down

0 comments on commit 15f966d

Please sign in to comment.