Posted over 1 year ago. Visible to the public. Repeats.

Capybara: Running tests with headless Chrome

Headless Chrome Archive is a way to run the Chrome browser without a visible window.

Configuring Capybara

Configure the Capybara driver like this:

Capybara.register_driver :selenium do |app| options = options.add_argument('--headless') unless ENV.key?('NO_HEADLESS') options.add_argument('--disable-infobars') options.add_emulation(device_metrics: { width: 1280, height: 960, touch: false }), browser: :chrome, options: options) end Selenium::WebDriver.logger.level = :error

Headless Chrome in legacy Capybara 1 projects

If you're working on a legacy project with Capybara version 1.x, the code below should do:

Capybara.register_driver :selenium do |app| args = [] args << '--headless' unless ENV.key?('NO_HEADLESS') args << '--disable-infobars' args << '--window-size=1280,960', browser: :chrome, args: args) end

Geordi users: Disable VNC

Note: In case you are using geordi Archive , it makes sense to disable its VNC wrapper around integration tests. Therefore create a file named .geordi.yml in the project root with the following content:

use_vnc: false

This is only necessary for geordi < 6 - see geordi -v.

Looking at the hidden browser

Option 1: Run without headless

You can call your tests with NO_HEADLESS=1 bundle exec cucumber to see the Chrome window for this test run.

Option 2: Remote debugging

In the code above, add an argument --remote-debugging-port=9222. You can then navigate to chrome://inspect in another browser to see the headless Chrome UI. You might need to disable this in parallel test runs (I haven't tested this).

More documentation here Archive

Does your version of Ruby on Rails still receive security updates?
Rails LTS provides security patches for unsupported versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2).

Owner of this card:

Henning Koch
Last edit:
14 days ago
by Michael Leimstädtner
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more