Summary
Capybara is a Ruby library for acceptance testing web applications that provides a domain-specific language for simulating how real users navigate and interact with pages, independent of the underlying driver.
What is Capybara?
Capybara abstracts browser or rack-level interactions behind a clean Ruby DSL. A test can instruct Capybara to visit a URL, fill in a form, click a button, and assert on visible content—without coupling the test to a specific browser automation tool. Drivers such as Rack::Test (fast, headless) or Selenium (real browser) are interchangeable.
Capybara integrates naturally with RSpec and Cucumber, making it a central component of BDD test suites for Ruby on Rails applications. Its API is designed to be readable by anyone familiar with the application's user interface.
Asynchronous content is handled automatically: Capybara waits for elements to appear before asserting, eliminating common timing failures in web tests.
Why is Capybara relevant?
- Driver agnostic: Switch between fast in-process tests and full browser automation without rewriting test logic
- Readable tests: The DSL mirrors user actions, keeping acceptance tests understandable to non-developers
- Rails ecosystem standard: De-facto choice for acceptance and integration testing in Ruby on Rails projects