Ir para conteúdo principal
Lucas Caton


O caminho certo para aprender React

70 videoaulas. Mais de 11 horas de conteúdo. Vários projetos desenvolvidos!

Quero saber mais

How to run your feature specs using Capybara and Headless Chrome

Enjoy faster testing!

Lucas Caton

Lucas Caton

Google has recently announced a way to run the Chrome browser in a headless environment. If you're using Capybara gem, you can easily start using headless Chrome. Without further ado, let's do it:
  1. Make sure you have one of the following Chrome versions:
  • 57+ on Linux
  • 59+ on macOS
  • 60+ on Windows
  1. Add (or update) the gem selenium-webdriver;
  2. Make sure you're using ChromeDriver version 2.30 or higher. You can install it by running:
  • brew install chromedriver on macOS;
  • apt-get install chromium-chromedriver on Debian/Ubuntu Linux.
  1. Add the following driver to your spec/support/capybara.rb, spec/spec_helper.rb, or spec/rails_helper.rb:
Capybara.javascript_driver = :selenium_chrome_headless
Or, if you need to use some custom options:
Capybara.register_driver :chrome do |app| app, browser: :chrome,
    options: %w[headless disable-gpu])

Capybara.javascript_driver = :chrome
Done, enjoy headless Chrome! ᕕ( ᐛ )ᕗ

You might get a warning like the following:
WARN Selenium [DEPRECATION] :args or :switches is deprecated. Use Selenium::WebDriver::Chrome::Options#add_argument instead.
Make sure you don't have another registered driver, I made this mistake myself and had an iphone driver, which was passing args in the old way and turned out to be the reason why I was getting the warning.

Post atualizado em 16/04/2018, 07:00:00