Read more

How to enable Chromedriver logging

Avatar
Arne Hartherz
September 26, 2019Software engineer at makandra GmbH

When using Chrome for Selenium tests, the chromedriver binary will be used to control Chrome. To debug problems that stem from Selenium's Chrome and/or Chromedriver, you might want to enable logging for the chromedriver itself. Here is how.

Option 1: Use Selenium::WebDriver::Service

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more

In your test setup, you may already have something like Capybara::Selenium::Driver.new(@app, browser: :chrome, options: ...), especially when passing options like device emulation.

Similar to options, simply add an extra key service and pass an instance of Selenium::WebDriver::Service like so:

service = ::Selenium::WebDriver::Service.chrome(args: { verbose: true, log_path: '/tmp/chromedriver.log' })
::Capybara::Selenium::Driver.new(@app, browser: :chrome, options: ..., service: service)

Note that version 3.x also supports passing the service arguments as driver_opts directly. However, this is deprecated and will be removed in version 4 of selenium-webdriver.

Option 2: Connect tests to a manually started chromedriver

If the above approach no longer works, or if you want to go bare metal, you can also start chromedriver yourself in a terminal on a custom port:

chromedriver --port=12345 --verbose --log-path=/tmp/chromedriver.log

Then configure Selenium to connect to that port. Like in option 1, you need to pass an extra key when creating your driver instance.

Capybara::Selenium::Driver.new(@app, browser: :chrome, options: ..., url: 'http://localhost:12345')

Note that you may omit the --log-path option to make chromedriver print to your terminal.

Posted by Arne Hartherz to makandra dev (2019-09-26 09:44)