Skip to content

Commit a90d7fb

Browse files
committed
[rb] add more logging to Selenium Manager
1 parent 6dad428 commit a90d7fb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

rb/.rubocop.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Layout/SpaceInsideHashLiteralBraces:
1616
EnforcedStyle: no_space
1717

1818
Metrics/AbcSize:
19-
Max: 28
19+
Max: 30
2020
Exclude:
2121
- 'lib/selenium/webdriver/remote/capabilities.rb'
2222
- 'lib/selenium/webdriver/remote/http/curb.rb'
@@ -35,8 +35,8 @@ Metrics/ClassLength:
3535
- 'lib/selenium/webdriver/common/driver.rb'
3636
- 'lib/selenium/webdriver/remote/bridge.rb'
3737
- 'lib/selenium/webdriver/remote/capabilities.rb'
38-
- 'spec/integration/selenium/webdriver/bidi/log_inspector_spec.rb'
3938
- 'spec/integration/selenium/webdriver/spec_support/test_environment.rb'
39+
- 'spec/**/*.rb'
4040

4141
Metrics/CyclomaticComplexity:
4242
Max: 9

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class << self
3333
# @param [Options] options browser options.
3434
# @return [String] the path to the correct driver.
3535
def driver_path(options)
36+
message = "driver for #{options.browser_name} not found; attempting to install with Selenium Manager"
37+
WebDriver.logger.warn(message)
38+
3639
unless options.is_a?(Options)
3740
raise ArgumentError, "SeleniumManager requires a WebDriver::Options instance, not a #{options.inspect}"
3841
end
@@ -46,6 +49,7 @@ def driver_path(options)
4649
command << '--browser-path'
4750
command << "\"#{options.binary.gsub('\ ', ' ').gsub(' ', '\ ')}\""
4851
end
52+
command << '--debug' if WebDriver.logger.debug?
4953

5054
location = run(command.join(' '))
5155
WebDriver.logger.debug("Driver found at #{location}")
@@ -82,8 +86,8 @@ def run(command)
8286

8387
begin
8488
stdout, stderr, status = Open3.capture3(command)
85-
json_output = JSON.parse(stdout)
86-
result = json_output['result']['message']
89+
json_output = stdout.empty? ? nil : JSON.parse(stdout)
90+
result = json_output&.dig('result', 'message')
8791
rescue StandardError => e
8892
raise Error::WebDriverError, "Unsuccessful command executed: #{command}", e.message
8993
end
@@ -93,7 +97,7 @@ def run(command)
9397
end
9498

9599
json_output['logs'].each do |log|
96-
WebDriver.logger.warn(log['message']) if log['level'] == 'WARN'
100+
WebDriver.logger.send(log['level'].downcase, log['message'])
97101
end
98102

99103
result

0 commit comments

Comments
 (0)