Logging Selenium commands
Each language adopts a distinctly different approach to logging information about the activity of the program.
Ruby uses a custom implementation of the default
Logger class with some interesting additional features.
By default, logs are sent to the console in
if you want to store the logs in a file, add this to your code:
Selenium::WebDriver.logger.output = '/path/to/selenium.log'
The basic levels for the Ruby logger are:
:debug similar to “verbose” and “very verbose”, so the default
To change the level of the logger:
Selenium::WebDriver.logger.level = :fatal
Warnings include everything we want users to be aware of by default. This is mostly used for deprecations. For various reasons, Selenium project does not follow standard Semantic Versioning practices. Our policy is to mark things as deprecated for 3 releases and then remove them. As such, Ruby logs deprecations as warnings, specifying what is changing, what needs to be used instead. It may include additional messages, and always includes an ID.
2022-12-24 16:07:09 WARN Selenium [DEPRECATION] [:jwp_caps] `Capabilities#version=` is deprecated. Use `Capabilities#browser_version=` instead.
Because these items can get annoying, we’ve provided an easy way to turn them off.
To turn off a specific warning, set the ID to ignore:
It accepts an
Array to turn off multiple IDs:
Selenium::WebDriver.logger.ignore(%i[jwp_caps pause pauses])
To turn off all deprecation notices:
This is where the most useful information gets logged. Selenium logs the endpoints and payloads sent to and received from the driver or server. This is a great way to see what Selenium is actually doing under the hood, and can be used to determine if it is Selenium code or driver code that is causing a problem. (Unfortunately, we can’t blame the driver if Selenium is sending incorrect syntax).
This is less useful information where we log things about the servers and the sockets, and header information, etc.
Debug mode is set if either
$DEBUG is true or
ENV['DEBUG'] has a value.
Check our contribution guidelines if you’d like to help.