Skip to content

Commit

Permalink
update how selenium manager logs (#12145)
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner authored Jun 5, 2023
1 parent f2c1192 commit 38e658a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
5 changes: 3 additions & 2 deletions java/src/org/openqa/selenium/manager/SeleniumManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class SeleniumManager {

private static final String SELENIUM_MANAGER = "selenium-manager";
private static final String EXE = ".exe";
private static final String INFO = "INFO";
private static final String WARN = "WARN";
private static final String DEBUG = "DEBUG";

Expand Down Expand Up @@ -135,7 +136,7 @@ private static String runCommand(String... command) {
if (logged.level.equalsIgnoreCase(WARN)) {
LOG.warning(logged.message);
}
if (logged.level.equalsIgnoreCase(DEBUG)) {
if (logged.level.equalsIgnoreCase(DEBUG) || logged.level.equalsIgnoreCase(INFO)) {
LOG.fine(logged.message);
}
});
Expand Down Expand Up @@ -209,7 +210,7 @@ private String getBrowserBinary(Capabilities options) {
* @return the location of the driver.
*/
public String getDriverPath(Capabilities options) {
LOG.info("Applicable driver not found; attempting to install with Selenium Manager (Beta)");
LOG.fine("Applicable driver not found; attempting to install with Selenium Manager (Beta)");
File binaryFile = getBinary();
if (binaryFile == null) {
return null;
Expand Down
4 changes: 2 additions & 2 deletions py/selenium/webdriver/common/selenium_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def driver_location(self, options: BaseOptions) -> str:
:Returns: The driver path to use
"""

logger.info("Applicable driver not found; attempting to install with Selenium Manager (Beta)")
logger.debug("Applicable driver not found; attempting to install with Selenium Manager (Beta)")

browser = options.capabilities["browserName"]

Expand Down Expand Up @@ -121,6 +121,6 @@ def run(args: List[str]) -> str:
for item in output["logs"]:
if item["level"] == "WARN":
logger.warning(item["message"])
if item["level"] == "DEBUG":
if item["level"] == "DEBUG" or item["level"] == "INFO":
logger.debug(item["message"])
return result
5 changes: 3 additions & 2 deletions rb/lib/selenium/webdriver/common/selenium_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def bin_path
# @return [String] the path to the correct driver.
def driver_path(options)
message = 'applicable driver not found; attempting to install with Selenium Manager (Beta)'
WebDriver.logger.info(message, id: :selenium_manager)
WebDriver.logger.debug(message, id: :selenium_manager)

unless options.is_a?(Options)
raise ArgumentError, "SeleniumManager requires a WebDriver::Options instance, not #{options.inspect}"
Expand Down Expand Up @@ -106,7 +106,8 @@ def run(*command)
end

(json_output&.fetch('logs') || []).each do |log|
WebDriver.logger.send(log['level'].downcase, log['message'], id: :selenium_manager)
level = log['level'].casecmp('info').zero? ? 'debug' : log['level'].downcase
WebDriver.logger.send(level, log['message'], id: :selenium_manager)
end

if status.exitstatus.positive?
Expand Down
26 changes: 7 additions & 19 deletions rb/spec/unit/selenium/webdriver/common/selenium_manager_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,16 @@ def stub_binary(binary)
describe 'self.driver_path' do
it 'errors if not an option' do
expect {
expect {
described_class.driver_path(Remote::Capabilities.new(browser_name: 'chrome'))
}.to raise_error(ArgumentError, /SeleniumManager requires a WebDriver::Options instance/)
}.to have_warning(:selenium_manager)
described_class.driver_path(Remote::Capabilities.new(browser_name: 'chrome'))
}.to raise_error(ArgumentError, /SeleniumManager requires a WebDriver::Options instance/)
end

it 'determines browser name by default' do
allow(described_class).to receive(:run)
allow(described_class).to receive(:binary).and_return('selenium-manager')
allow(Platform).to receive(:assert_executable)

expect {
described_class.driver_path(Options.chrome)
}.to have_warning(:selenium_manager)
described_class.driver_path(Options.chrome)

expect(described_class).to have_received(:run)
.with('selenium-manager', '--browser', 'chrome', '--output', 'json')
Expand All @@ -101,9 +97,7 @@ def stub_binary(binary)
allow(Platform).to receive(:assert_executable)
options = Options.chrome(browser_version: 1)

expect {
described_class.driver_path(options)
}.to have_warning(:selenium_manager)
described_class.driver_path(options)

expect(described_class).to have_received(:run)
.with('selenium-manager',
Expand All @@ -119,9 +113,7 @@ def stub_binary(binary)
allow(Platform).to receive(:assert_executable)
options = Options.chrome(proxy: proxy)

expect {
described_class.driver_path(options)
}.to have_warning(:selenium_manager)
described_class.driver_path(options)

expect(described_class).to have_received(:run)
.with('selenium-manager',
Expand All @@ -136,9 +128,7 @@ def stub_binary(binary)
allow(Platform).to receive(:assert_executable)
options = Options.chrome(binary: '/path/to/browser')

expect {
described_class.driver_path(options)
}.to have_warning(:selenium_manager)
described_class.driver_path(options)

expect(described_class).to have_received(:run)
.with('selenium-manager', '--browser', 'chrome', '--output', 'json', '--browser-path', '/path/to/browser')
Expand All @@ -150,9 +140,7 @@ def stub_binary(binary)
allow(Platform).to receive(:assert_executable)
options = Options.chrome(binary: '/path to/the/browser')

expect {
described_class.driver_path(options)
}.to have_warning(:selenium_manager)
described_class.driver_path(options)

expect(described_class).to have_received(:run)
.with('selenium-manager', '--browser', 'chrome', '--output', 'json',
Expand Down

0 comments on commit 38e658a

Please sign in to comment.