Capybara Setup With Chrome Headless Webdriver on CircleCI With Ruby on Rails Project
Selenium WebDriver tutorial for Rails project and RSpec with Capybara gems.
Join the DZone community and get the full member experience.Join For Free
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 using it on the CI.
This triggered me 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, and Chrome headless together.
Add Capybara and Selenium WebDriver
If you already have the gems in your
Gemfile then ensure you have the latest version with
bundle update capybara selenium-webdriver.
If you want to make sure Capybara feature specs will work on your development machine, run the following:
If your feature specs fail, then upgrade the driver because you may have installed old one.
Add a config file for Capybara:
Ensure you load config files from the
Example Feature Spec
We can create an example feature spec to test if everything works:
Now 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 an example of the
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, you can set it to
.circleci/config.yml and use dynamic RSpec specs allocation across CI nodes with the
knapsack_pro gem and Queue Mode to get optimal test suite split to save as much time as possible.
You can learn how RSpec test suite parallelisation works in this one minute video.
Now you are good to push your code to a repository and see how your Capybara feature specs work with Chrome Headless on CircleCI 2.0.
Published at DZone with permission of Artur Trzop. See the original article here.
Opinions expressed by DZone contributors are their own.