Skip to content

Commit ed313de

Browse files
committed
[rb] implement proxy support for Selenium Manager
1 parent 632df3e commit ed313de

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

rb/lib/selenium/webdriver/common/logger.rb

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Logger
4141
:debug?,
4242
:info?,
4343
:warn?,
44-
:error, :error?,
44+
:error?,
4545
:fatal, :fatal?,
4646
:level
4747

@@ -137,6 +137,17 @@ def info(message, id: [], &block)
137137
discard_or_log(:info, message, id, &block)
138138
end
139139

140+
#
141+
# Used to supply information that suggests an error occurred
142+
#
143+
# @param [String] message
144+
# @param [Symbol, Array<Sybmol>] id
145+
# @yield see #deprecate
146+
#
147+
def error(message, id: [], &block)
148+
discard_or_log(:error, message, id, &block)
149+
end
150+
140151
#
141152
# Used to supply information that suggests action be taken by user
142153
#

rb/lib/selenium/webdriver/common/selenium_manager.rb

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ def driver_path(options)
4040
raise ArgumentError, "SeleniumManager requires a WebDriver::Options instance, not #{options.inspect}"
4141
end
4242

43+
command = generate_command(binary, options)
44+
45+
location = run(*command)
46+
WebDriver.logger.debug("Driver found at #{location}", id: :selenium_manager)
47+
Platform.assert_executable location
48+
49+
location
50+
end
51+
52+
private
53+
54+
def generate_command(binary, options)
4355
command = [binary, '--browser', options.browser_name, '--output', 'json']
4456
if options.browser_version
4557
command << '--browser-version'
@@ -49,17 +61,14 @@ def driver_path(options)
4961
command << '--browser-path'
5062
command << options.binary.gsub('\\', '\\\\\\')
5163
end
64+
if options.proxy
65+
command << '--proxy'
66+
(command << options.proxy.ssl) || options.proxy.http
67+
end
5268
command << '--debug' if WebDriver.logger.debug?
53-
54-
location = run(*command)
55-
WebDriver.logger.debug("Driver found at #{location}", id: :selenium_manager)
56-
Platform.assert_executable location
57-
58-
location
69+
command
5970
end
6071

61-
private
62-
6372
# @return [String] the path to the correct selenium manager
6473
def binary
6574
@binary ||= begin
@@ -92,12 +101,12 @@ def run(*command)
92101
raise Error::WebDriverError, "Unsuccessful command executed: #{command}", e.message
93102
end
94103

95-
if status.exitstatus.positive?
96-
raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{result}#{stderr}"
104+
(json_output&.fetch('logs') || []).each do |log|
105+
WebDriver.logger.send(log['level'].downcase, log['message'], id: :selenium_manager)
97106
end
98107

99-
json_output['logs'].each do |log|
100-
WebDriver.logger.send(log['level'].downcase, log['message'], id: :selenium_manager)
108+
if status.exitstatus.positive?
109+
raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{result}#{stderr}"
101110
end
102111

103112
result

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,28 @@ def stub_binary(binary)
106106
}.to have_warning(:selenium_manager)
107107

108108
expect(described_class).to have_received(:run)
109-
.with('selenium-manager', '--browser', 'chrome', '--output', 'json', '--browser-version', 1)
109+
.with('selenium-manager',
110+
'--browser', 'chrome',
111+
'--output', 'json',
112+
'--browser-version', 1)
113+
end
114+
115+
it 'uses proxy if specified' do
116+
proxy = Selenium::WebDriver::Proxy.new(ssl: 'proxy')
117+
allow(described_class).to receive(:run)
118+
allow(described_class).to receive(:binary).and_return('selenium-manager')
119+
allow(Platform).to receive(:assert_executable)
120+
options = Options.chrome(proxy: proxy)
121+
122+
expect {
123+
described_class.driver_path(options)
124+
}.to have_warning(:selenium_manager)
125+
126+
expect(described_class).to have_received(:run)
127+
.with('selenium-manager',
128+
'--browser', 'chrome',
129+
'--output', 'json',
130+
'--proxy', 'proxy')
110131
end
111132

112133
it 'uses browser location if specified' do

0 commit comments

Comments
 (0)