Setting Up Capybara

Capybara allows an automated test to simulate a user interaction with a browser. When simulating this interaction, Capybara works in conjunction with a driver, using the simple Capybara API to determine what elements to interact with and using the driver to manage the actual interaction. By default, Capybara uses a native Ruby library that doesn’t manage JavaScript interactions, but it can be configured to use a headless browser such as PhantomJS, headless Chrome, or Selenium to allow JavaScript interactions to be simulated.

Capybara and RSpec

Capybara is part of the default Rails Gemfile in Rails 5.1 and later. If you’re using an earlier version, add Capybara to your Gemfile’s test group:

 gem "capybara"

In either case, ...

Get Rails 5 Test Prescriptions now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.