How to Enable Chromedriver Logging in Ruby Capybara with Selenium

How to enable ChromeDriver logging in Ruby Capybara with Selenium?

You have already added logging prefs in capabilities.

Also, you can create a method to store the logs where ever you need. Here is the method I use to write logs on a specific folder you need. You can call this method in after hooks. Also, you can store as artifacts if you want to see in any CI/CD application

 def capture_browser_logs
errors = Capybara.page.driver.browser.manage.logs.get(:browser)
.select { |e| e.level == "SEVERE" && e.message.present? }
.map(&:message)
.to_a
return if errors.none?
message = errors.join("\n\n")

# writes console errors to a log file
log_file_path = Rails.root.join("tmp", "smoke_tests", "console_logs", "js_errors.log")
FileUtils.mkdir_p(log_file_path.dirname) unless File.directory?(log_file_path.dirname)

logging_destination = if ENV["RAILS_LOG_TO_STDOUT"].present? && ENV["RAILS_LOG_TO_STDOUT"].to_s == "true"
STDOUT
else
log_file_path
end

logger = Logger.new(logging_destination)
logger.error(message)
end

Enable/view console.log messages in headless Chrome

When Chrome changed to w3c mode by default (v75) it changed loggingPrefs to goog:loggingPrefs to be spec compliant. Try setting goog:loggingPrefs instead.

Rails: Capyabra / Selenium Chrome-Driver Settings

It is not an error,it is a deprecation warning.

The gem chromedriver-helper is deprecated

NOTICE: This gem is out of support as of 2019-03-31 Please use
https://github.com/titusfortner/webdrivers instead. See
https://github.com/flavorjones/chromedriver-helper/issues/83 for
details.

In you gemfile:

group :test do
gem 'webdrivers', '~> 3.0'
end

group :development, :test do
gem 'capybara'
end

I'll suggest you to move capybara in the development and test's group, and also update it, if is possible.

Cromedriver `driver.manage.logs.get(:browser)` fails on chromedriver 75.0.3770.8

Capybara 3.24 now works around this issue when used with chromedriver >= 75.0.3770.90

How to enable chromedriver logging in from the selenium webdriver

In comment of chrome.js, there is a way to enable logging for chromewebdriver

 *
* By default, every Chrome session will use a single driver service, which is
* started the first time a {@link Driver} instance is created and terminated
* when this process exits. The default service will inherit its environment
* from the current process and direct all output to /dev/null. You may obtain
* a handle to this default service using
* {@link #getDefaultService getDefaultService()} and change its configuration
* with {@link #setDefaultService setDefaultService()}.
*
* You may also create a {@link Driver} with its own driver service. This is
* useful if you need to capture the server's log output for a specific session:
*
* let chrome = require('selenium-webdriver/chrome');
*
* let service = new chrome.ServiceBuilder()
* .loggingTo('/my/log/file.txt')
* .enableVerboseLogging()
* .build();
*
* let options = new chrome.Options();
* // configure browser options ...
*
* let driver = chrome.Driver.createSession(options, service);
*

Also you have other option:

  • Running ChromeDriver as a standalone process

Since the ChromeDriver implements the wire protocol, it is fully compatible with any RemoteWebDriver client. Simply start up the ChromeDriver executable (that works as a server) with arguments --log-path and --verbose, create a client, and away you go:

WebDriver driver = new RemoteWebDriver(
"http://localhost:9515",
DesiredCapabilities.chrome()
);
driver.get("http://www.google.com");

ChromeDriver Unable to add Performance Logging in Selenium Java

I was able to find the answer on at SeleniumHQ issues. Essentially, CapabilityType.LOGGING_PREFS is broken in this version of ChromeDriver. I changed the line

options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

to

options.setCapability("goog:loggingPrefs", logPrefs);

the preference name was changed to goog:loggingPrefs to be W3C compliant. I was able to collect network logs after this change.



Related Topics



Leave a reply



Submit