I’ve been using Capybara-WebKit for a long time but while switching from CircleCI 1.0 to CircleCI 2.0 I had some problems to use it on the CI.
This triggered to try Chrome Headless with Selenium Webdriver. I will show you how to configure Circle CI 2.0 and your Ruby on Rails project to use capybara/selenium/chrome headless together.
If you already had the gems in your Gemfile then ensure you have latest version with bundle update capybara selenium-webdriver.
If you want to make sure Capybara feature specs will work on your development machine:
If your feature specs fail then upgrade the driver because you may have installed old one.
Configure Capybara
Add config file for Capybara:
Ensure you load config files from spec/support directory:
Example feature spec
We can create example feature spec to test if everything works:
And run tests on your development machine with bin/rspec spec/features/home_spec.rb or bundle exec rspec spec/features/home_spec.rb.
Configure CircleCI 2.0 to run Chrome headless
Here is example .circleci/config.yml:
Speed up your tests with Circle CI parallelisation
If your feature specs are very long you can save some time by running multiple parallel CI nodes. For instance set it to 6 in .circleci/config.yml and use dynamic RSpec specs allocation across CI nodes with knapsack_pro gem and Queue Mode to get optimal test suite split to save as much time as possible.