Skip to content

Commit

Permalink
rb - Remove deprecated and inapplicable options from browser bridges
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 18, 2016
1 parent 4438400 commit 8973aee
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 96 deletions.
45 changes: 11 additions & 34 deletions rb/lib/selenium/webdriver/chrome/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,12 @@ def quit
private

def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.chrome }
args = opts.delete(:args) || opts.delete(:switches)
native_events = opts.delete(:native_events)
verbose = opts.delete(:verbose)
profile = opts.delete(:profile)
detach = opts.delete(:detach)
proxy = opts.delete(:proxy)
no_website_testing_defaults = opts.delete(:no_website_testing_defaults)
prefs = opts.delete(:prefs)
caps = opts.delete(:desired_capabilities) { Remote::Capabilities.chrome }
args = opts.delete(:args) || opts.delete(:switches)
profile = opts.delete(:profile)
detach = opts.delete(:detach)
proxy = opts.delete(:proxy)
prefs = opts.delete(:prefs)

unless opts.empty?
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
Expand All @@ -91,43 +88,23 @@ def create_capabilities(opts)
unless args.is_a? Array
raise ArgumentError, ':args must be an Array of Strings'
end

chrome_options['args'] = args.map(&:to_s)
end

if profile
data = profile.as_json

chrome_options['profile'] = data['zip']
chrome_options['extensions'] = data['extensions']
end

chrome_options['binary'] = Chrome.path if Chrome.path
chrome_options['nativeEvents'] = true if native_events
chrome_options['verbose'] = true if verbose
chrome_options['detach'] = true if detach
chrome_options['noWebsiteTestingDefaults'] = true if no_website_testing_defaults
chrome_options['prefs'] = prefs if prefs
chrome_options['extensions'] = profile.as_json['extensions'] if profile
chrome_options['binary'] = Chrome.path if Chrome.path
chrome_options['detach'] = true if detach
chrome_options['prefs'] = prefs if prefs

caps['chromeOptions'] = chrome_options
caps['proxy'] = proxy if proxy

# legacy options - for chromedriver < 17.0.963.0
caps['chrome.switches'] = chrome_options['args'] if chrome_options.member?('args')
%w[binary detach extensions nativeEvents noWebsiteTestingDefaults prefs profile verbose].each do |key|
caps["chrome.#{key}"] = chrome_options[key] if chrome_options.member?(key)
end

caps
end

def extract_service_args(opts)
args = []

if opts.key?(:service_log_path)
args << "--log-path=#{opts.delete(:service_log_path)}"
end

args << "--log-path=#{opts.delete(:service_log_path)}" if opts.key?(:service_log_path)
args
end
end # Bridge
Expand Down
28 changes: 2 additions & 26 deletions rb/lib/selenium/webdriver/edge/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ def initialize(opts = {})
if opts.key?(:url)
url = opts.delete(:url)
else
@service = Service.new(Edge.driver_path, Service::DEFAULT_PORT, *extract_service_args(opts))
@service = Service.new(Edge.driver_path, Service::DEFAULT_PORT)
@service.host = 'localhost' if @service.host == '127.0.0.1'
@service.start

url = @service.uri
end

caps = create_capabilities(opts)
caps ||= Remote::W3CCapabilities.edge

remote_opts = {
url: url,
Expand Down Expand Up @@ -70,30 +70,6 @@ def quit
@service.stop if @service
end

private

def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) { Remote::W3CCapabilities.edge }
page_load_strategy = opts.delete(:page_load_strategy) || 'normal'

unless opts.empty?
raise ArgumentError, "unknown option#{'s' if opts.size != 1}: #{opts.inspect}"
end

caps['page_load_strategy'] = page_load_strategy

caps
end

def extract_service_args(opts)
args = []

if opts.key?(:service_log_path)
args << "--log-path=#{opts.delete(:service_log_path)}"
end

args
end
end # Bridge
end # Edge
end # WebDriver
Expand Down
9 changes: 1 addition & 8 deletions rb/lib/selenium/webdriver/firefox/w3c_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(opts = {})
caps = opts[:desired_capabilities] ||= Remote::W3CCapabilities.firefox
Binary.path = caps[:firefox_binary] if caps[:firefox_binary]

@service = Service.new(Firefox.driver_path, Service::DEFAULT_PORT, *extract_service_args(opts))
@service = Service.new(Firefox.driver_path, Service::DEFAULT_PORT)
@service.start

opts[:url] = @service.uri
Expand All @@ -51,13 +51,6 @@ def quit
ensure
@service.stop if @service
end

private

def extract_service_args(opts)
service_log_path = opts.delete(:service_log_path)
service_log_path ? ["--log-path=#{service_log_path}"] : []
end
end # W3CBridge
end # Firefox
end # WebDriver
Expand Down
7 changes: 0 additions & 7 deletions rb/lib/selenium/webdriver/safari/apple_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ def quit
ensure
@service.stop if @service
end

private

def extract_service_args(opts)
service_log_path = opts.delete(:service_log_path)
service_log_path ? ["--log-path=#{service_log_path}"] : []
end
end # AppleBridge
end # Safari
end # WebDriver
Expand Down
21 changes: 0 additions & 21 deletions rb/spec/unit/selenium/webdriver/chrome/bridge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ module Chrome
allow(Service).to receive(:new).and_return(service)
end

it 'sets the nativeEvents capability' do
Bridge.new(http_client: http, native_events: true)

expect(caps['chromeOptions']['nativeEvents']).to be true
expect(caps['chrome.nativeEvents']).to be true
end

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

Expand All @@ -57,13 +50,6 @@ module Chrome
expect(caps['proxy']).to eq(proxy)
end

it 'sets the chrome.verbose capability' do
Bridge.new(http_client: http, verbose: true)

expect(caps['chromeOptions']['verbose']).to be true
expect(caps['chrome.verbose']).to be true
end

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

Expand All @@ -85,13 +71,6 @@ module Chrome
expect(caps['chrome.detach']).to be true
end

it 'lets the user override chrome.noWebsiteTestingDefaults' do
Bridge.new(http_client: http, no_website_testing_defaults: true)

expect(caps['chromeOptions']['noWebsiteTestingDefaults']).to be true
expect(caps['chrome.noWebsiteTestingDefaults']).to be true
end

it 'uses the user-provided server URL if given' do
expect(Service).not_to receive(:new)
expect(http).to receive(:server_url=).with(URI.parse('http://example.com'))
Expand Down

0 comments on commit 8973aee

Please sign in to comment.