Skip to content

Commit

Permalink
Cleanup deprecated capabilities/options processing
Browse files Browse the repository at this point in the history
  • Loading branch information
p0deje committed Apr 18, 2019
1 parent b56d110 commit 752077a
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 110 deletions.
16 changes: 0 additions & 16 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,6 @@ def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.chrome }
options = opts.delete(:options) { Options.new }

args = opts.delete(:args) || opts.delete(:switches)
if args
WebDriver.logger.deprecate ':args or :switches', 'Selenium::WebDriver::Chrome::Options#add_argument'
raise ArgumentError, ':args must be an Array of Strings' unless args.is_a? Array

args.each { |arg| options.add_argument(arg.to_s) }
end

profile = opts.delete(:profile)
if profile
profile = profile.as_json
Expand All @@ -94,14 +86,6 @@ def create_capabilities(opts)
detach = opts.delete(:detach)
options.add_option(:detach, true) if detach

prefs = opts.delete(:prefs)
if prefs
WebDriver.logger.deprecate ':prefs', 'Selenium::WebDriver::Chrome::Options#add_preference'
prefs.each do |key, value|
options.add_preference(key, value)
end
end

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

Expand Down
15 changes: 0 additions & 15 deletions rb/lib/selenium/webdriver/firefox/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,6 @@ def quit
def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.firefox }
options = opts.delete(:options) { Options.new }

firefox_options = opts.delete(:firefox_options)
if firefox_options
WebDriver.logger.deprecate ':firefox_options', 'Selenium::WebDriver::Firefox::Options'
firefox_options.each do |key, value|
options.add_option(key, value)
end
end

profile = opts.delete(:profile)
if profile
WebDriver.logger.deprecate ':profile', 'Selenium::WebDriver::Firefox::Options#profile='
options.profile = profile
end

options = options.as_json
caps.merge!(options) unless options.empty?

Expand Down
13 changes: 0 additions & 13 deletions rb/lib/selenium/webdriver/ie/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@ def quit
def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.internet_explorer }
options = opts.delete(:options) { Options.new }

if opts.delete(:introduce_flakiness_by_ignoring_security_domains)
WebDriver.logger.deprecate ':introduce_flakiness_by_ignoring_security_domains',
'Selenium::WebDriver::IE::Options#ignore_protected_mode_settings='
options.ignore_protected_mode_settings = true
end

native_events = opts.delete(:native_events)
unless native_events.nil?
WebDriver.logger.deprecate ':native_events', 'Selenium::WebDriver::IE::Options#native_events='
options.native_events = native_events
end

options = options.as_json
caps.merge!(options) unless options.empty?

Expand Down
15 changes: 1 addition & 14 deletions rb/lib/selenium/webdriver/remote/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class Capabilities
# remote-specific
:remote_session_id,

# TODO: (AR) deprecate in favor of Firefox::Options?
:accessibility_checks,
:device,

# TODO: (AR) deprecate compatibility with OSS-capabilities
:implicit_timeout,
:page_load_timeout,
Expand Down Expand Up @@ -154,12 +150,6 @@ def json_create(data)
# Remote Server Specific
caps[:remote_session_id] = data.delete('webdriver.remote.sessionid') if data.key?('webdriver.remote.sessionid')

# Marionette Specific
caps[:accessibility_checks] = data.delete('moz:accessibilityChecks') if data.key?('moz:accessibilityChecks')
caps[:profile] = data.delete('moz:profile') if data.key?('moz:profile')
caps[:rotatable] = data.delete('rotatable') if data.key?('rotatable')
caps[:device] = data.delete('device') if data.key?('device')

# any remaining pairs will be added as is, with no conversion
caps.merge!(data)

Expand Down Expand Up @@ -233,10 +223,7 @@ def as_json(*)
hash['proxy']['proxyType'] &&= hash['proxy']['proxyType'].downcase
hash['proxy']['noProxy'] = hash['proxy']['noProxy'].split(', ') if hash['proxy']['noProxy'].is_a?(String)
end
when String, :firefox_binary
if key == :firefox_binary && value
WebDriver.logger.deprecate(':firefox_binary capabilitiy', 'Selenium::WebDriver::Firefox::Options#binary')
end
when String
hash[key.to_s] = value
when Symbol
hash[camel_case(key.to_s)] = value
Expand Down
13 changes: 0 additions & 13 deletions rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@ module Selenium
module WebDriver
module Chrome
describe Driver, only: {driver: :chrome} do
it 'accepts an array of custom command line arguments' do
create_driver!(args: ['--user-agent=foo;bar']) do |driver|
driver.navigate.to url_for('click_jacker.html')

ua = driver.execute_script 'return window.navigator.userAgent'
expect(ua).to eq('foo;bar')
end
end

it 'raises ArgumentError if :args is not an Array' do
expect { create_driver!(args: '--foo') }.to raise_error(ArgumentError, ':args must be an Array of Strings')
end

it 'gets and sets network conditions' do
driver.network_conditions = {offline: false, latency: 56, throughput: 789}
expect(driver.network_conditions).to eq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ module WebDriver

expect(caps.accept_insecure_certs).to be == false
expect(caps.page_load_strategy).to be == 'normal'
expect(caps.accessibility_checks).to be == false
expect(caps.implicit_timeout).to be_zero
expect(caps.page_load_timeout).to be == 300000
expect(caps.script_timeout).to be == 30000
Expand Down
35 changes: 1 addition & 34 deletions rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,6 @@ module Chrome
allow(Service).to receive(:new).and_return(service)
end

it 'sets the args capability' do
Driver.new(http_client: http, args: %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['goog:chromeOptions'][:args]).to eq(%w[--foo=bar])
end

it 'sets the proxy capabilitiy' do
proxy = Proxy.new(http: 'localhost:1234')
Driver.new(http_client: http, proxy: proxy)
Expand All @@ -65,12 +53,6 @@ module Chrome
expect(caps['chrome.detach']).to be nil
end

it 'sets the prefs capability' do
Driver.new(http_client: http, prefs: {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)

Expand All @@ -96,12 +78,11 @@ module Chrome

context 'with custom desired capabilities' do
subject(:build_new_driver) do
Driver.new(http_client: http, desired_capabilities: custom_caps, args: driver_args)
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 'takes desired capabilities' do
expect(http).to receive(:call) do |_, _, payload|
Expand All @@ -112,20 +93,6 @@ module Chrome
build_new_driver
end

context 'with direct arguments' do
let(:cap_opts) { {'goog:chromeOptions' => {args: %w[foo bar]}} }
let(:driver_args) { %w[baz] }

it 'lets direct arguments take precedence over capabilities' do
expect(http).to receive(:call) do |_, _, payload|
expect(payload[:capabilities][:firstMatch][0]['goog:chromeOptions'][:args]).to eq(driver_args)
resp
end

build_new_driver
end
end

context 'with empty driver options' do
let(:cap_opts) { {'goog:chromeOptions' => {args: %w[foo bar]}} }

Expand Down
4 changes: 0 additions & 4 deletions rb/spec/unit/selenium/webdriver/remote/capabilities_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ module Remote
caps = Capabilities.new(browser_name: 'firefox', 'extension:customCapability': true)
expect(caps).to eq(Capabilities.json_create(caps.as_json))
end

it 'does not camel case the :firefox_binary capability' do
expect(Capabilities.new(firefox_binary: '/foo/bar').as_json).to include('firefox_binary')
end
end
end # Remote
end # WebDriver
Expand Down

0 comments on commit 752077a

Please sign in to comment.