Skip to content

Commit

Permalink
Refactor custom desired_capabilities spec in driver_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
artplan1 authored and p0deje committed Jul 1, 2018
1 parent 178b07e commit 6bb3e14
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ module Chrome
expect(caps[:proxy]).to eq(proxy)
end

it 'does not set goog:chromeOptions by default' do
Driver.new(http_client: http)

expect(caps['goog:chromeOptions']).to be nil
end

it 'does not set the chrome.detach capability by default' do
Driver.new(http_client: http)

Expand Down Expand Up @@ -86,44 +92,55 @@ module Chrome
expect(caps['goog:chromeOptions'][:extensions]).to eq(profile_data[:extensions])
end

it 'takes desired capabilities' do
custom_caps = Remote::Capabilities.new
custom_caps[:chrome_options] = {'foo' => 'bar'}
it 'handshakes protocol' do
expect(Remote::Bridge).to receive(:handshake)
Driver.new(http_client: http)
end

expect(http).to receive(:call) do |_, _, payload|
expect(payload[:desiredCapabilities][:chrome_options]).to include('foo' => 'bar')
resp
context 'with custom desired capabilities' do
subject(:build_new_driver) do
Driver.new(http_client: http, desired_capabilities: custom_caps, args: driver_args)
end

Driver.new(http_client: http, desired_capabilities: custom_caps)
end
let(:custom_caps) { Remote::Capabilities.new(cap_opts) }
let(:cap_opts) { {chrome_options: {'foo' => 'bar'}} }
let(:driver_args) { [] }

it 'lets direct arguments take presedence over capabilities' do
custom_caps = Remote::Capabilities.new
custom_caps['goog:chromeOptions'] = {'args' => %w[foo bar]}
it 'takes desired capabilities' do
expect(http).to receive(:call) do |_, _, payload|
expect(payload[:desiredCapabilities][:chrome_options]).to include('foo' => 'bar')
resp
end

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

Driver.new(http_client: http, desired_capabilities: custom_caps, args: %w[baz])
end
context 'with direct arguments' do
let(:cap_opts) { {'goog:chromeOptions' => {args: %w[foo bar]}} }
let(:driver_args) { %w[baz] }

it 'does not merge empty options' do
custom_caps = Remote::Capabilities.new('goog:chromeOptions' => {args: %w[foo bar]})
it 'lets direct arguments take precedence over capabilities' do
expect(http).to receive(:call) do |_, _, payload|
expect(payload[:desiredCapabilities]['goog:chromeOptions'][:args]).to eq(driver_args)
resp
end

expect(http).to receive(:call) do |_, _, payload|
expect(payload[:desiredCapabilities]['goog:chromeOptions'][:args]).to eq(%w[foo bar])
resp
build_new_driver
end
end

Driver.new(http_client: http, desired_capabilities: custom_caps)
end
context 'with empty driver options' do
let(:cap_opts) { {'goog:chromeOptions' => {args: %w[foo bar]}} }

it 'handshakes protocol' do
expect(Remote::Bridge).to receive(:handshake)
Driver.new(http_client: http)
it 'does not merge empty options' do
expect(http).to receive(:call) do |_, _, payload|
expect(payload[:desiredCapabilities]['goog:chromeOptions'][:args]).to eq(%w[foo bar])
resp
end

build_new_driver
end
end
end
end
end # Chrome
Expand Down

0 comments on commit 6bb3e14

Please sign in to comment.