Skip to content

Commit 054467a

Browse files
authored
[rb] have Selenium Manager binary locate drivers on PATH (#12345)
1 parent 6a48692 commit 054467a

15 files changed

Lines changed: 9 additions & 157 deletions

File tree

rb/lib/selenium/webdriver/common/driver_finder.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class DriverFinder
2323
def self.path(options, klass)
2424
path = klass.driver_path
2525
path = path.call if path.is_a?(Proc)
26-
path ||= Platform.find_binary(klass::EXECUTABLE)
2726

2827
path ||= begin
2928
SeleniumManager.driver_path(options) unless options.is_a?(Remote::Capabilities)

rb/lib/selenium/webdriver/common/platform.rb

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,6 @@ def ci
6262
end
6363
end
6464

65-
def bitsize
66-
@bitsize ||= if defined?(FFI::Platform::ADDRESS_SIZE)
67-
FFI::Platform::ADDRESS_SIZE
68-
elsif defined?(FFI)
69-
FFI.type_size(:pointer) == 4 ? 32 : 64
70-
elsif jruby?
71-
Integer(ENV_JAVA['sun.arch.data.model'])
72-
else
73-
1.size == 4 ? 32 : 64
74-
end
75-
end
76-
7765
def jruby?
7866
engine == :jruby
7967
end
@@ -158,43 +146,6 @@ def exit_hook
158146
at_exit { yield if Process.pid == pid }
159147
end
160148

161-
def find_binary(*binary_names)
162-
paths = ENV['PATH'].split(File::PATH_SEPARATOR)
163-
164-
if windows?
165-
binary_names.map! { |n| "#{n}.exe" }
166-
binary_names.dup.each { |n| binary_names << n.gsub('exe', 'bat') }
167-
end
168-
169-
binary_names.each do |binary_name|
170-
paths.each do |path|
171-
full_path = File.join(path, binary_name)
172-
full_path = unix_path(full_path) if windows?
173-
exe = Dir.glob(full_path).find { |f| File.executable?(f) }
174-
return exe if exe
175-
end
176-
end
177-
178-
nil
179-
end
180-
181-
def find_in_program_files(*binary_names)
182-
paths = [
183-
ENV.fetch('PROGRAMFILES', '\\Program Files'),
184-
ENV.fetch('ProgramFiles(x86)', '\\Program Files (x86)'),
185-
ENV.fetch('ProgramW6432', '\\Program Files')
186-
]
187-
188-
paths.each do |root|
189-
binary_names.each do |name|
190-
exe = File.join(root, name)
191-
return exe if File.executable?(exe)
192-
end
193-
end
194-
195-
nil
196-
end
197-
198149
def localhost
199150
info = Socket.getaddrinfo 'localhost', 80, Socket::AF_INET, Socket::SOCK_STREAM
200151

rb/lib/selenium/webdriver/remote/server_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(response)
2525
if response.is_a? String
2626
super(response)
2727
else
28-
super("status code #{response.code}; payload #{response.payload.to_s}")
28+
super("status code #{response.code}; payload #{response.payload}")
2929
end
3030
end
3131
end # ServerError

rb/spec/integration/selenium/server_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ module Selenium
3434
end
3535

3636
it 'downloads specified version' do
37-
@location = described_class.download('4.9.0')
37+
@location = described_class.download('4.9.0')
3838

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

4343
it 'starts and stops server' do
4444
@location = described_class.download

rb/spec/integration/selenium/webdriver/chrome/service_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module Chrome
3030
after { service_manager.stop }
3131

3232
it 'auto uses chromedriver' do
33-
allow(Platform).to receive(:find_binary)
3433
expect(service_manager.uri).to be_a(URI)
3534
end
3635
end

rb/spec/integration/selenium/webdriver/edge/service_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module Edge
3030
after { service_manager.stop }
3131

3232
it 'auto uses edgedriver' do
33-
allow(Platform).to receive(:find_binary)
3433
expect(service_manager.uri).to be_a(URI)
3534
end
3635
end

rb/spec/integration/selenium/webdriver/firefox/service_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ module Firefox
3030
after { service_manager.stop }
3131

3232
it 'auto uses geckodriver' do
33-
allow(Platform).to receive(:find_binary)
3433
service_manager = service.launch
3534
expect(service_manager.uri).to be_a(URI)
3635
end

rb/spec/unit/selenium/webdriver/chrome/service_spec.rb

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ module Chrome
5252
end
5353

5454
it 'does not create args by default' do
55-
allow(Platform).to receive(:find_binary).and_return(service_path)
56-
5755
service = described_class.new
5856

5957
expect(service.extra_args).to be_empty
@@ -72,16 +70,12 @@ module Chrome
7270
end
7371

7472
it 'uses provided args' do
75-
allow(Platform).to receive(:find_binary).and_return(service_path)
76-
7773
service = described_class.chrome(args: ['--foo', '--bar'])
7874

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

8278
it 'uses args when passed in as a Hash' do
83-
allow(Platform).to receive(:find_binary).and_return(service_path)
84-
8579
expect {
8680
service = described_class.new(args: {log_path: '/path/to/log',
8781
verbose: true})

rb/spec/unit/selenium/webdriver/common/driver_finder_spec.rb

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,7 @@ module WebDriver
5454
expect(Platform).to have_received(:assert_executable).with('path')
5555
end
5656

57-
it 'uses path from PATH' do
58-
allow(SeleniumManager).to receive(:driver_path)
59-
allow(Platform).to receive(:assert_file)
60-
allow(Platform).to receive(:assert_executable)
61-
allow(Platform).to receive(:find_binary).and_return('path')
62-
63-
described_class.path(options, service)
64-
65-
expect(SeleniumManager).not_to have_received(:driver_path)
66-
expect(Platform).to have_received(:assert_executable).with('path')
67-
end
68-
6957
it 'gives original error if not found by Selenium Manager' do
70-
allow(Platform).to receive(:find_binary)
7158
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)
7259

7360
expect {
@@ -108,20 +95,7 @@ module WebDriver
10895
expect(Platform).to have_received(:assert_executable).with('path')
10996
end
11097

111-
it 'uses path from PATH' do
112-
allow(SeleniumManager).to receive(:driver_path)
113-
allow(Platform).to receive(:assert_file)
114-
allow(Platform).to receive(:assert_executable)
115-
allow(Platform).to receive(:find_binary).and_return('path')
116-
117-
described_class.path(options, service)
118-
119-
expect(SeleniumManager).not_to have_received(:driver_path)
120-
expect(Platform).to have_received(:assert_executable).with('path')
121-
end
122-
12398
it 'gives original error if not found by Selenium Manager' do
124-
allow(Platform).to receive(:find_binary)
12599
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)
126100

127101
expect {
@@ -162,20 +136,7 @@ module WebDriver
162136
expect(Platform).to have_received(:assert_executable).with('path')
163137
end
164138

165-
it 'uses path from PATH' do
166-
allow(SeleniumManager).to receive(:driver_path)
167-
allow(Platform).to receive(:assert_file)
168-
allow(Platform).to receive(:assert_executable)
169-
allow(Platform).to receive(:find_binary).and_return('path')
170-
171-
described_class.path(options, service)
172-
173-
expect(SeleniumManager).not_to have_received(:driver_path)
174-
expect(Platform).to have_received(:assert_executable).with('path')
175-
end
176-
177139
it 'gives original error if not found by Selenium Manager' do
178-
allow(Platform).to receive(:find_binary)
179140
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)
180141

181142
expect {
@@ -216,20 +177,7 @@ module WebDriver
216177
expect(Platform).to have_received(:assert_executable).with('path')
217178
end
218179

219-
it 'uses path from PATH' do
220-
allow(SeleniumManager).to receive(:driver_path)
221-
allow(Platform).to receive(:assert_file)
222-
allow(Platform).to receive(:assert_executable)
223-
allow(Platform).to receive(:find_binary).and_return('path')
224-
225-
described_class.path(options, service)
226-
227-
expect(SeleniumManager).not_to have_received(:driver_path)
228-
expect(Platform).to have_received(:assert_executable).with('path')
229-
end
230-
231180
it 'gives original error if not found by Selenium Manager' do
232-
allow(Platform).to receive(:find_binary)
233181
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)
234182

235183
expect {
@@ -270,20 +218,7 @@ module WebDriver
270218
expect(Platform).to have_received(:assert_executable).with('path')
271219
end
272220

273-
it 'uses path from PATH' do
274-
allow(SeleniumManager).to receive(:driver_path)
275-
allow(Platform).to receive(:assert_file)
276-
allow(Platform).to receive(:assert_executable)
277-
allow(Platform).to receive(:find_binary).and_return('path')
278-
279-
described_class.path(options, service)
280-
281-
expect(SeleniumManager).not_to have_received(:driver_path)
282-
expect(Platform).to have_received(:assert_executable).with('path')
283-
end
284-
285221
it 'gives original error if not found by Selenium Manager' do
286-
allow(Platform).to receive(:find_binary)
287222
allow(SeleniumManager).to receive(:driver_path).and_raise(Error::WebDriverError)
288223

289224
expect {

rb/spec/unit/selenium/webdriver/common/service_spec.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ module WebDriver
3131
end
3232

3333
describe 'browser shortcuts' do
34-
before { allow(Platform).to receive(:find_binary).and_return(service_path) }
35-
3634
let(:args) { %w[--foo --bar] }
3735

3836
it 'creates Chrome instance' do

0 commit comments

Comments
 (0)