Selenium: ruby - Unable to alter log level for capturing remote chrome browser console logs

Created on 31 Mar 2017  路  13Comments  路  Source: SeleniumHQ/selenium

@relates to https://github.com/SeleniumHQ/selenium/pull/3474#issuecomment-290826192

Meta -

Client OS: OSX
Docker image: selenium/standalone-chrome:3.1.0
Selenium Version: v3.3.0 ruby

Context

I'm trying to capture the console.debug and console.info from chrome with v3.3.0, but Selenium::WebDriver.logger.level = :debug from the docs seems to only affect selenium logging itself. The docs section doesn't mention altering specific loggers.

How would I adjust the level of logs from remote chrome (only)? I tried the following with no luck:

Capybara.register_driver $default_driver do |app|
  Capybara::Selenium::Driver.new(app, {
    browser: :remote,
    url: 'http://127.0.0.1:4444/wd/hub',
    desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome
  })
end

Selenium::WebDriver::Driver.for(:remote).logger.level = :debug

The javascript module appears to use capabilities but I see no such equivalent when browsing the ruby code equivalent.

Expected Behavior -

I can set the browser console log level for retrieving logs (perhaps like the javascript module using capabilities).

Actual Behavior -

I cannot set the browser log level via ruby.

Steps to reproduce -

No code exists to allow this behavior.

Most helpful comment

I figured it out, though the wiki docs need to be updated in multiple places. I have no permissions to do so, so I'll leave this issue open with suggestions:

Add to https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#logging:

Browser log level

You may adjust the browser log level using capabilities, such as:

Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: {browser: 'ALL'})

(please expand on this, I only found this value through trial and error, looking at posts for other languages).

Update chrome capabilities because of dead links to loggingPrefs https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#chrome-specific:

(same as above?)

All 13 comments

The chrome capabilities document regarding loggingPrefs is broken, it goes to google which loggingPref section points to https://code.google.com/p/selenium/wiki/DesiredCapabilities#JSON_object which lands on Selenium Google Code Issue Archive.

I figured it out, though the wiki docs need to be updated in multiple places. I have no permissions to do so, so I'll leave this issue open with suggestions:

Add to https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#logging:

Browser log level

You may adjust the browser log level using capabilities, such as:

Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: {browser: 'ALL'})

(please expand on this, I only found this value through trial and error, looking at posts for other languages).

Update chrome capabilities because of dead links to loggingPrefs https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#chrome-specific:

(same as above?)

Hi,

We cannot update chromedriver's link back to our capabilities, but it should point here:

https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#loggingpreferences-json-object

We are currently implementing a Chrome Options class that will make it much easier to set the log level. Once we do that, I'll update the wiki.

As far as the wiki for Ruby-Bindings#logging, that logging is not for browser console logging but only for actions within the Ruby bindings

We are currently implementing a Chrome Options class that will make it much easier to set the log level. Once we do that, I'll update the wiki.

@lmtierney did this ever happen?

Yes, Chrome::Options class was added recently, though it doesn't expose any specific API for handling logging prefs. We need to figure out the way to make it accessible via Chrome::Options, because right now it only provides Chrome-specific settings.

The example suggested in comment should still work.

Ah yes, I was mistaken with my previous comment. The logging prefs isn't part of the Chrome options but rather the normal capabilities so it wouldn't be in the chromeOptions capability

@p0deje I guess it should technically be through the Capabilities class https://github.com/SeleniumHQ/selenium/wiki/DesiredCapabilities#loggingpreferences-json-object although it's not a w3c capability but rather a selenium (and Chromedriver) capability.

Yes, it is achievable via Capabilities class:

caps = Selenium::WebDriver::Remote::Capabilities.chrome(loggingPrefs: {browser: 'ALL'})
driver = Selenium::WebDriver.for(:chrome, desired_capabilities: caps)

Where are these logs output to? I can't find any documentation on this topic either.

They can be retrieved later by driver.manage.logs.get(:browser).

Had some problems accessing the logs in my capybara + selenium-webdriver + chrome headless setup, with the help from this thread I found that they where accessible by doing page.driver.browser.manage.logs.get(:browser). Just writing it down for reference, maybe someone else will find it useful.

yeah... this is a bit weird - looks like Chrome::Options was a way to abstract away passing desired_capabilities but if we want to adjust loggingPrefs we still need to use desired_capabilities directly. And we can't even use desired_capabilities solely because args and stuff are deprecated in favor of Chrome::Options so now we have to use both APIs

Chrome::Options abstract Chrome-specific caps, while loggingPrefs is a generic one supported by all drivers.

Was this page helpful?
0 / 5 - 0 ratings