Skip to content

Commit

Permalink
Use goog:chromeOptions when sending Chrome options capabilities
Browse files Browse the repository at this point in the history
It has been introduced in ChromeDriver 2.31 and is compliant to W3C
spec. Please note this this commit requires you to have ChromeDriver 2.31
at least.
  • Loading branch information
p0deje committed May 18, 2018
1 parent 6404eef commit 0ba8188
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def create_capabilities(opts)
end

options = options.as_json
caps[:chrome_options] = options unless options.empty?
caps.merge!(options) unless options.empty?

caps[:proxy] = opts.delete(:proxy) if opts.key?(:proxy)
caps[:proxy] ||= opts.delete('proxy') if opts.key?('proxy')
Expand Down
5 changes: 4 additions & 1 deletion rb/lib/selenium/webdriver/chrome/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Options
attr_reader :args, :prefs, :options, :emulation, :extensions, :encoded_extensions
attr_accessor :binary

KEY = 'goog:chromeOptions'.freeze

#
# Create a new Options instance.
#
Expand Down Expand Up @@ -175,7 +177,8 @@ def as_json(*)
opts[:extensions] = extensions if extensions.any?
opts[:mobileEmulation] = @emulation unless @emulation.empty?
opts[:prefs] = @prefs unless @prefs.empty?
opts

{KEY => opts}
end
end # Options
end # Chrome
Expand Down
18 changes: 9 additions & 9 deletions rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ module Chrome
it 'sets the args capability' do
Driver.new(http_client: http, args: %w[--foo=bar])

expect(caps[:chrome_options][:args]).to eq(%w[--foo=bar])
expect(caps['goog:chromeOptions'][:args]).to eq(%w[--foo=bar])
end

it 'sets the args capability from switches' do
Driver.new(http_client: http, switches: %w[--foo=bar])

expect(caps[:chrome_options][:args]).to eq(%w[--foo=bar])
expect(caps['goog:chromeOptions'][:args]).to eq(%w[--foo=bar])
end

it 'sets the proxy capabilitiy' do
Expand All @@ -54,20 +54,20 @@ module Chrome
it 'does not set the chrome.detach capability by default' do
Driver.new(http_client: http)

expect(caps[:chrome_options]).to be nil
expect(caps['goog:chromeOptions']).to eq({})
expect(caps['chrome.detach']).to be nil
end

it 'sets the prefs capability' do
Driver.new(http_client: http, prefs: {foo: 'bar'})

expect(caps[:chrome_options][:prefs]).to eq(foo: 'bar')
expect(caps['goog:chromeOptions'][:prefs]).to eq(foo: 'bar')
end

it 'lets the user override chrome.detach' do
Driver.new(http_client: http, detach: true)

expect(caps[:chrome_options][:detach]).to be true
expect(caps['goog:chromeOptions'][:detach]).to be true
end

it 'raises an ArgumentError if args is not an Array' do
Expand All @@ -83,8 +83,8 @@ module Chrome
Driver.new(http_client: http, profile: profile)

profile_data = profile.as_json
expect(caps[:chrome_options][:args].first).to include(profile_data[:directory])
expect(caps[:chrome_options][:extensions]).to eq(profile_data[:extensions])
expect(caps['goog:chromeOptions'][:args].first).to include(profile_data[:directory])
expect(caps['goog:chromeOptions'][:extensions]).to eq(profile_data[:extensions])
end

it 'takes desired capabilities' do
Expand All @@ -101,10 +101,10 @@ module Chrome

it 'lets direct arguments take presedence over capabilities' do
custom_caps = Remote::Capabilities.new
custom_caps[:chrome_options] = {'args' => %w[foo bar]}
custom_caps['goog:chromeOptions'] = {'args' => %w[foo bar]}

expect(http).to receive(:call) do |_, _, payload|
expect(payload[:desiredCapabilities][:chrome_options][:args]).to eq(['baz'])
expect(payload[:desiredCapabilities]['goog:chromeOptions'][:args]).to eq(['baz'])
resp
end

Expand Down
12 changes: 6 additions & 6 deletions rb/spec/unit/selenium/webdriver/chrome/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ module Chrome
options: {foo: :bar},
emulation: {c: 3})
json = opts.as_json
expect(json[:args]).to eq(['foo'])
expect(json[:binary]).to eq('/foo/bar')
expect(json[:prefs]).to include(a: 1)
expect(json[:extensions]).to include('bar')
expect(json[:foo]).to eq(:bar)
expect(json[:mobileEmulation]).to include(c: 3)
expect(json['goog:chromeOptions'][:args]).to eq(['foo'])
expect(json['goog:chromeOptions'][:binary]).to eq('/foo/bar')
expect(json['goog:chromeOptions'][:prefs]).to include(a: 1)
expect(json['goog:chromeOptions'][:extensions]).to include('bar')
expect(json['goog:chromeOptions'][:foo]).to eq(:bar)
expect(json['goog:chromeOptions'][:mobileEmulation]).to include(c: 3)
end
end
end # Options
Expand Down

0 comments on commit 0ba8188

Please sign in to comment.