Skip to content

Commit 6dad428

Browse files
committed
[rb] Using json output with Selenium Manager
Work done for #11365
1 parent 30ae31c commit 6dad428

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def driver_path(options)
3737
raise ArgumentError, "SeleniumManager requires a WebDriver::Options instance, not a #{options.inspect}"
3838
end
3939

40-
command = [binary, '--browser', options.browser_name]
40+
command = [binary, '--browser', options.browser_name, '--output', 'json']
4141
if options.browser_version
4242
command << '--browser-version'
4343
command << options.browser_version
@@ -82,15 +82,21 @@ def run(command)
8282

8383
begin
8484
stdout, stderr, status = Open3.capture3(command)
85+
json_output = JSON.parse(stdout)
86+
result = json_output['result']['message']
8587
rescue StandardError => e
8688
raise Error::WebDriverError, "Unsuccessful command executed: #{command}", e.message
8789
end
8890

8991
if status.exitstatus.positive?
90-
raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{stdout}#{stderr}"
92+
raise Error::WebDriverError, "Unsuccessful command executed: #{command}\n#{result}#{stderr}"
9193
end
9294

93-
stdout.split("\n").last.gsub("INFO\t", '')
95+
json_output['logs'].each do |log|
96+
WebDriver.logger.warn(log['message']) if log['level'] == 'WARN'
97+
end
98+
99+
result
94100
end
95101
end
96102
end # SeleniumManager

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module WebDriver
8585

8686
described_class.driver_path(Options.chrome)
8787

88-
expect(described_class).to have_received(:run).with('selenium-manager --browser chrome')
88+
expect(described_class).to have_received(:run).with('selenium-manager --browser chrome --output json')
8989
end
9090

9191
it 'uses browser version if specified' do
@@ -96,7 +96,8 @@ module WebDriver
9696

9797
described_class.driver_path(options)
9898

99-
expect(described_class).to have_received(:run).with('selenium-manager --browser chrome --browser-version 1')
99+
expect(described_class).to have_received(:run)
100+
.with('selenium-manager --browser chrome --output json --browser-version 1')
100101
end
101102

102103
it 'uses browser location if specified' do
@@ -108,7 +109,7 @@ module WebDriver
108109
described_class.driver_path(options)
109110

110111
expect(described_class).to have_received(:run)
111-
.with('selenium-manager --browser chrome --browser-path "/path/to/browser"')
112+
.with('selenium-manager --browser chrome --output json --browser-path "/path/to/browser"')
112113
end
113114

114115
it 'properly escapes plain spaces in browser location' do
@@ -120,7 +121,7 @@ module WebDriver
120121
described_class.driver_path(options)
121122

122123
expect(described_class).to have_received(:run)
123-
.with('selenium-manager --browser chrome --browser-path "/path\ to/the/browser"')
124+
.with('selenium-manager --browser chrome --output json --browser-path "/path\ to/the/browser"')
124125
end
125126

126127
it 'properly escapes escaped spaces in browser location' do
@@ -132,7 +133,7 @@ module WebDriver
132133
described_class.driver_path(options)
133134

134135
expect(described_class).to have_received(:run)
135-
.with('selenium-manager --browser chrome --browser-path "/path\ to/the/browser"')
136+
.with('selenium-manager --browser chrome --output json --browser-path "/path\ to/the/browser"')
136137
end
137138
end
138139
end

0 commit comments

Comments
 (0)