Skip to content

Commit

Permalink
rb - implement :service_args parameter for all drivers to pass in com…
Browse files Browse the repository at this point in the history
…mand line switches
  • Loading branch information
titusfortner committed Sep 18, 2016
1 parent 24ce572 commit 6d52426
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 31 deletions.
3 changes: 3 additions & 0 deletions rb/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ ruby_library(name = "edge",
"lib/selenium/webdriver/edge/**/*.rb",
"lib/selenium/webdriver/edge.rb"
],
resources = [
{ "//javascript/webdriver/atoms:getAttribute": "rb/lib/selenium/webdriver/atoms/getAttribute.js"}
],
deps = [":common"]
)

Expand Down
20 changes: 15 additions & 5 deletions rb/lib/selenium/webdriver/chrome/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ module Chrome
class Bridge < Remote::Bridge
def initialize(opts = {})
port = opts.delete(:port) || Service::DEFAULT_PORT
service_args = opts.delete(:service_args) || {}
if opts[:service_log_path]
service_args.merge!(service_log_path: opts.delete(:service_log_path))
end

unless opts.key?(:url)
@service = Service.new(Chrome.driver_path, port, *extract_service_args(opts))
@service = Service.new(Chrome.driver_path, port, *extract_service_args(service_args))
@service.start
opts[:url] = @service.uri
end
Expand Down Expand Up @@ -83,10 +88,15 @@ def create_capabilities(opts)
caps
end

def extract_service_args(opts)
args = []
args << "--log-path=#{opts.delete(:service_log_path)}" if opts.key?(:service_log_path)
args
def extract_service_args(args)
service_args = []
service_args << "--log-path=#{args.delete(:service_log_path)}" if args.key?(:service_log_path)
service_args << "--url-base=#{args.delete(:url_base)}" if args.key?(:url_base)
service_args << "--port-server=#{args.delete(:port_server)}" if args.key?(:port_server)
service_args << "--whitelisted-ips=#{args.delete(:whitelisted_ips)}" if args.key?(:whitelisted_ips)
service_args << "--verbose=#{args.delete(:verbose)}" if args.key?(:whitelisted_ips)
service_args << "--silent=#{args.delete(:silent)}" if args.key?(:whitelisted_ips)

This comment has been minimized.

Copy link
@BrianHawley

BrianHawley Sep 19, 2016

Contributor

@titusfortner are you sure that args.key?(:whitelisted_ips) is what you should be checking for these two?

This comment has been minimized.

Copy link
@titusfortner

titusfortner Sep 19, 2016

Author Member

yup, that's a bad copy/paste. thanks for the catch!

service_args
end
end # Bridge
end # Chrome
Expand Down
12 changes: 11 additions & 1 deletion rb/lib/selenium/webdriver/edge/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ module Edge
class Bridge < Remote::W3CBridge
def initialize(opts = {})
port = opts.delete(:port) || Service::DEFAULT_PORT
service_args = opts.delete(:service_args) || {}
unless opts.key?(:url)
@service = Service.new(Edge.driver_path, port)
@service = Service.new(Edge.driver_path, port, *extract_service_args(service_args))
@service.host = 'localhost' if @service.host == '127.0.0.1'
@service.start
opts[:url] = @service.uri
Expand Down Expand Up @@ -60,6 +61,15 @@ def quit
@service.stop if @service
end

private

def extract_service_args(args = {})
service_args = []
service_args << "–host=#{args[:host]}" if args.key? :host
service_args << "–package=#{args[:package]}" if args.key? :package
service_args << "-verbose" if args[:verbose] == true
service_args
end
end # Bridge
end # Edge
end # WebDriver
Expand Down
14 changes: 13 additions & 1 deletion rb/lib/selenium/webdriver/firefox/w3c_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ class W3CBridge < Remote::W3CBridge
def initialize(opts = {})
port = opts.delete(:port) || Service::DEFAULT_PORT
opts[:desired_capabilities] = create_capabilities(opts)
service_args = opts.delete(:service_args) || {}

@service = Service.new(Firefox.driver_path, port)
@service = Service.new(Firefox.driver_path, port, *extract_service_args(service_args))
@service.start
opts[:url] = @service.uri

Expand Down Expand Up @@ -61,6 +62,17 @@ def create_capabilities(opts)
Binary.path = caps[:firefox_options][:binary] if caps[:firefox_options].key?(:binary)
caps
end

def extract_service_args(args = {})
service_args = []
service_args << "--binary=#{args[:binary]}" if args.key?(:binary)
service_args << "–-log=#{args[:log]}" if args.key?(:log)
service_args << "–-marionette-port=#{args[:marionette_port]}" if args.key?(:marionette_port)
service_args << "–-host=#{args[:host]}" if args.key?(:host)
service_args << "–-port=#{args[:port]}" if args.key?(:port)
service_args
end

end # W3CBridge
end # Firefox
end # WebDriver
Expand Down
22 changes: 15 additions & 7 deletions rb/lib/selenium/webdriver/ie/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ module IE
class Bridge < Remote::Bridge
def initialize(opts = {})
port = opts.delete(:port) || Service::DEFAULT_PORT

@service = Service.new(IE.driver_path, port, *extract_service_args(opts))
service_args = opts.delete(:service_args) || {}
service_args = match_legacy(opts, service_args)
@service = Service.new(IE.driver_path, port, *extract_service_args(service_args))
@service.start
opts[:url] = @service.uri

Expand All @@ -55,13 +56,20 @@ def quit

private

def extract_service_args(opts)
args = []
args << "--log-level=#{opts.delete(:log_level).to_s.upcase}" if opts[:log_level]
args << "--log-file=#{opts.delete(:log_file)}" if opts[:log_file]
args << "--implementation=#{opts.delete(:implementation).to_s.upcase}" if opts[:implementation]
def match_legacy(opts, args)
args[:log_level] = opts.delete(:log_level) if opts.key?(:log_level)
args[:log_file] = opts.delete(:log_file) if opts.key?(:log_file)
args[:implementation] = opts.delete(:implementation) if opts.key?(:implementation)
args
end

def extract_service_args(args)
service_args = []
service_args << "--log-level=#{args.delete(:log_level).to_s.upcase}" if args.key?(:log_level)
service_args << "--log-file=#{args.delete(:log_file)}" if args.key?(:log_file)
service_args << "--implementation=#{args.delete(:implementation).to_s.upcase}" if args.key?(:implementation)
service_args
end
end # Bridge
end # IE
end # WebDriver
Expand Down
11 changes: 9 additions & 2 deletions rb/lib/selenium/webdriver/safari/apple_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ module Safari
# @api private
class AppleBridge < Remote::Bridge
def initialize(opts = {})
port = opts.delete(:port) || Service::DEFAULT_PORT
opts[:desired_capabilities] ||= Remote::Capabilities.safari
port = opts.delete(:port) || Service::DEFAULT_PORT
service_args = opts.delete(:service_args) || {}

@service = Service.new(Safari.driver_path, port, *extract_service_args(opts))
@service = Service.new(Safari.driver_path, port, *extract_service_args(service_args))
@service.start
opts[:url] = @service.uri

Expand All @@ -38,6 +39,12 @@ def quit
ensure
@service.stop if @service
end

private

def extract_service_args(args = {})
["–host=#{args[:port]}"] if args.key? :port
end
end # AppleBridge
end # Safari
end # WebDriver
Expand Down
57 changes: 42 additions & 15 deletions rb/spec/integration/selenium/webdriver/firefox/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,52 @@ def restart_remote_server
end
end

it 'takes a binary path as an argument' do
pending "Set ENV['ALT_FIREFOX_BINARY'] to test this" unless ENV['ALT_FIREFOX_BINARY']
begin
driver1 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt.dup
# Remote needs to implement firefox options
not_compliant_on driver: :remote do
it 'takes a binary path as an argument' do
pending "Set ENV['ALT_FIREFOX_BINARY'] to test this" unless ENV['ALT_FIREFOX_BINARY']
begin
driver1 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt.dup

default_version = driver1.capabilities.version
expect { driver1.capabilities.browser_version }.to_not raise_exception NoMethodError
driver1.quit
default_version = driver1.capabilities.version
expect { driver1.capabilities.browser_version }.to_not raise_exception NoMethodError
driver1.quit

caps = Remote::Capabilities.firefox(firefox_options: {binary: ENV['ALT_FIREFOX_BINARY']})
@opt[:desired_capabilities] = caps
driver2 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt
caps = Remote::Capabilities.firefox(firefox_options: {binary: ENV['ALT_FIREFOX_BINARY']})
@opt[:desired_capabilities] = caps
driver2 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt

expect(driver2.capabilities.version).to_not eql(default_version)
expect { driver2.capabilities.browser_version }.to_not raise_exception NoMethodError
driver2.quit
ensure
Firefox::Binary.reset_path!
end
end

it 'gives precedence to firefox options versus argument switch' do
pending "Set ENV['ALT_FIREFOX_BINARY'] to test this" unless ENV['ALT_FIREFOX_BINARY']
begin
driver1 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt.dup

default_path = Firefox::Binary.path
default_version = driver1.capabilities.version
driver1.quit

caps = Remote::Capabilities.firefox(firefox_options: {binary: ENV['ALT_FIREFOX_BINARY']},
service_args: {binary: default_path})
@opt[:desired_capabilities] = caps
driver2 = Selenium::WebDriver.for GlobalTestEnv.driver, @opt

expect(driver2.capabilities.version).to_not eql(default_version)
expect { driver2.capabilities.browser_version }.to_not raise_exception NoMethodError
driver2.quit
ensure
Firefox::Binary.reset_path!
end

expect(driver2.capabilities.version).to_not eql(default_version)
expect { driver2.capabilities.browser_version }.to_not raise_exception NoMethodError
driver2.quit
ensure
Firefox::Binary.reset_path!
end

end

# https://github.com/mozilla/geckodriver/issues/58
Expand Down

0 comments on commit 6d52426

Please sign in to comment.