Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] have Selenium Manager binary locate drivers on PATH #12345

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rb/lib/selenium/webdriver/common/driver_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class DriverFinder
def self.path(options, klass)
path = klass.driver_path
path = path.call if path.is_a?(Proc)
path ||= Platform.find_binary(klass::EXECUTABLE)

path ||= begin
SeleniumManager.driver_path(options) unless options.is_a?(Remote::Capabilities)
Expand Down
49 changes: 0 additions & 49 deletions rb/lib/selenium/webdriver/common/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ def ci
end
end

def bitsize
@bitsize ||= if defined?(FFI::Platform::ADDRESS_SIZE)
FFI::Platform::ADDRESS_SIZE
elsif defined?(FFI)
FFI.type_size(:pointer) == 4 ? 32 : 64
elsif jruby?
Integer(ENV_JAVA['sun.arch.data.model'])
else
1.size == 4 ? 32 : 64
end
end

def jruby?
engine == :jruby
end
Expand Down Expand Up @@ -158,43 +146,6 @@ def exit_hook
at_exit { yield if Process.pid == pid }
end

def find_binary(*binary_names)
paths = ENV['PATH'].split(File::PATH_SEPARATOR)

if windows?
binary_names.map! { |n| "#{n}.exe" }
binary_names.dup.each { |n| binary_names << n.gsub('exe', 'bat') }
end

binary_names.each do |binary_name|
paths.each do |path|
full_path = File.join(path, binary_name)
full_path = unix_path(full_path) if windows?
exe = Dir.glob(full_path).find { |f| File.executable?(f) }
return exe if exe
end
end

nil
end

def find_in_program_files(*binary_names)
paths = [
ENV.fetch('PROGRAMFILES', '\\Program Files'),
ENV.fetch('ProgramFiles(x86)', '\\Program Files (x86)'),
ENV.fetch('ProgramW6432', '\\Program Files')
]

paths.each do |root|
binary_names.each do |name|
exe = File.join(root, name)
return exe if File.executable?(exe)
end
end

nil
end

def localhost
info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM

Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/remote/server_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def initialize(response)
if response.is_a? String
super(response)
else
super("status code #{response.code}; payload #{response.payload.to_s}")
super("status code #{response.code}; payload #{response.payload}")
end
end
end # ServerError
Expand Down
8 changes: 4 additions & 4 deletions rb/spec/integration/selenium/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ module Selenium
end

it 'downloads specified version' do
@location = described_class.download('4.9.0')
@location = described_class.download('4.9.0')

expect(File.exist?(@location)).to be true
expect(@location).to eq('selenium-server-4.9.0.jar')
end
expect(File.exist?(@location)).to be true
expect(@location).to eq('selenium-server-4.9.0.jar')
end

it 'starts and stops server' do
@location = described_class.download
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Chrome
after { service_manager.stop }

it 'auto uses chromedriver' do
allow(Platform).to receive(:find_binary)
expect(service_manager.uri).to be_a(URI)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Edge
after { service_manager.stop }

it 'auto uses edgedriver' do
allow(Platform).to receive(:find_binary)
expect(service_manager.uri).to be_a(URI)
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ module Firefox
after { service_manager.stop }

it 'auto uses geckodriver' do
allow(Platform).to receive(:find_binary)
service_manager = service.launch
expect(service_manager.uri).to be_a(URI)
end
Expand Down
6 changes: 0 additions & 6 deletions rb/spec/unit/selenium/webdriver/chrome/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ module Chrome
end

it 'does not create args by default' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new

expect(service.extra_args).to be_empty
Expand All @@ -72,16 +70,12 @@ module Chrome
end

it 'uses provided args' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.chrome(args: ['--foo', '--bar'])

expect(service.extra_args).to eq ['--foo', '--bar']
end

it 'uses args when passed in as a Hash' do
allow(Platform).to receive(:find_binary).and_return(service_path)

expect {
service = described_class.new(args: {log_path: '/path/to/log',
verbose: true})
Expand Down
65 changes: 0 additions & 65 deletions rb/spec/unit/selenium/webdriver/common/driver_finder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,7 @@ module WebDriver
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'uses path from PATH' do
allow(SeleniumManager).to receive(:driver_path)
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
allow(Platform).to receive(:find_binary).and_return('path')

described_class.path(options, service)

expect(SeleniumManager).not_to have_received(:driver_path)
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'gives original error if not found by Selenium Manager' do
allow(Platform).to receive(:find_binary)
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)

expect {
Expand Down Expand Up @@ -108,20 +95,7 @@ module WebDriver
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'uses path from PATH' do
allow(SeleniumManager).to receive(:driver_path)
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
allow(Platform).to receive(:find_binary).and_return('path')

described_class.path(options, service)

expect(SeleniumManager).not_to have_received(:driver_path)
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'gives original error if not found by Selenium Manager' do
allow(Platform).to receive(:find_binary)
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)

expect {
Expand Down Expand Up @@ -162,20 +136,7 @@ module WebDriver
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'uses path from PATH' do
allow(SeleniumManager).to receive(:driver_path)
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
allow(Platform).to receive(:find_binary).and_return('path')

described_class.path(options, service)

expect(SeleniumManager).not_to have_received(:driver_path)
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'gives original error if not found by Selenium Manager' do
allow(Platform).to receive(:find_binary)
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)

expect {
Expand Down Expand Up @@ -216,20 +177,7 @@ module WebDriver
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'uses path from PATH' do
allow(SeleniumManager).to receive(:driver_path)
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
allow(Platform).to receive(:find_binary).and_return('path')

described_class.path(options, service)

expect(SeleniumManager).not_to have_received(:driver_path)
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'gives original error if not found by Selenium Manager' do
allow(Platform).to receive(:find_binary)
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)

expect {
Expand Down Expand Up @@ -270,20 +218,7 @@ module WebDriver
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'uses path from PATH' do
allow(SeleniumManager).to receive(:driver_path)
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
allow(Platform).to receive(:find_binary).and_return('path')

described_class.path(options, service)

expect(SeleniumManager).not_to have_received(:driver_path)
expect(Platform).to have_received(:assert_executable).with('path')
end

it 'gives original error if not found by Selenium Manager' do
allow(Platform).to receive(:find_binary)
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)

expect {
Expand Down
2 changes: 0 additions & 2 deletions rb/spec/unit/selenium/webdriver/common/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ module WebDriver
end

describe 'browser shortcuts' do
before { allow(Platform).to receive(:find_binary).and_return(service_path) }

let(:args) { %w[--foo --bar] }

it 'creates Chrome instance' do
Expand Down
6 changes: 0 additions & 6 deletions rb/spec/unit/selenium/webdriver/edge/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,19 @@ module Edge
end

it 'does not create args by default' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new

expect(service.extra_args).to be_empty
end

it 'uses provided args' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new(args: ['--foo', '--bar'])

expect(service.extra_args).to eq ['--foo', '--bar']
end

# This is deprecated behavior
it 'uses args when passed in as a Hash' do
allow(Platform).to receive(:find_binary).and_return(service_path)

expect {
service = described_class.new(args: {log_path: '/path/to/log',
verbose: true})
Expand Down
6 changes: 0 additions & 6 deletions rb/spec/unit/selenium/webdriver/firefox/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,18 @@ module Firefox
end

it 'does not create args by default' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new

expect(service.extra_args).to be_empty
end

it 'uses provided args' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new(args: ['--foo', '--bar'])

expect(service.extra_args).to eq ['--foo', '--bar']
end

it 'uses args when passed in as a Hash' do
allow(Platform).to receive(:find_binary).and_return(service_path)

expect {
service = described_class.new(args: {log: '/path/to/log',
marionette_port: 4})
Expand Down
6 changes: 0 additions & 6 deletions rb/spec/unit/selenium/webdriver/ie/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,19 @@ module IE
end

it 'does not create args by default' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new

expect(service.extra_args).to be_empty
end

it 'uses provided args' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new(args: ['--foo', '--bar'])

expect(service.extra_args).to eq ['--foo', '--bar']
end

# This is deprecated behavior
it 'uses args when passed in as a Hash' do
allow(Platform).to receive(:find_binary).and_return(service_path)

expect {
service = described_class.new(args: {log_file: '/path/to/log',
silent: true})
Expand Down
4 changes: 2 additions & 2 deletions rb/spec/unit/selenium/webdriver/safari/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def expect_request(body: nil, endpoint: nil)
end

it 'does not require any parameters' do
allow(Platform).to receive(:find_binary).and_return('/path/to/safaridriver')
allow(SeleniumManager).to receive(:driver_path).and_return('/path/to/safaridriver')
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
expect_request
Expand All @@ -72,7 +72,7 @@ def expect_request(body: nil, endpoint: nil)
end

it 'accepts provided Options as sole parameter' do
allow(Platform).to receive(:find_binary).and_return('path/to/safaridriver')
allow(SeleniumManager).to receive(:driver_path).and_return('/path/to/safaridriver')
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
opts = {automatic_inspection: true}
Expand Down
8 changes: 2 additions & 6 deletions rb/spec/unit/selenium/webdriver/safari/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ module Safari
end

it 'does not create args by default' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new

expect(service.extra_args).to be_empty
Expand All @@ -71,8 +69,6 @@ module Safari
end

it 'uses provided args' do
allow(Platform).to receive(:find_binary).and_return(service_path)

service = described_class.new(args: ['--foo', '--bar'])

expect(service.extra_args).to eq ['--foo', '--bar']
Expand Down Expand Up @@ -101,7 +97,7 @@ module Safari
end

it 'is created when :url is not provided' do
allow(Platform).to receive(:find_binary).and_return('/path/to/safaridriver')
allow(SeleniumManager).to receive(:driver_path).and_return('/path/to/safaridriver')
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
allow(described_class).to receive(:new).and_return(service)
Expand All @@ -112,7 +108,7 @@ module Safari
end

it 'accepts :service without creating a new instance' do
allow(Platform).to receive(:find_binary).and_return('path/to/safaridriver')
allow(SeleniumManager).to receive(:driver_path).and_return('/path/to/safaridriver')
allow(Platform).to receive(:assert_file)
allow(Platform).to receive(:assert_executable)
allow(described_class).to receive(:new)
Expand Down