Skip to content

Capybara

Ruby library for automated tests that drive a web app the way a real user would.

Stars
10.2k
Forks
1.5k
Licence
MIT
Language
Ruby
Last update
1 months ago
Type
Library

What it is

Capybara is a Ruby library for writing acceptance tests for web applications. Tests use readable commands like clicking a button or filling in a field, and Capybara simulates a user interacting with the app. It can run against a fast headless driver or a real browser through Selenium, and works out of the box with Rails and Rack apps.

  • Write a test that signs a user in by filling in a form and checking for a success message
  • Run the same test suite headless for speed or in a real browser for JavaScript-heavy pages
  • Test forms, links, buttons, and modals in a web app

Great for

  • Ruby and Rails developers writing feature or system tests
  • Teams that want the same test code to run headless or in a real browser
  • Projects already using RSpec, Cucumber, Minitest, or Test::Unit

Not ideal for

  • Teams not using Ruby, since the library is written for Ruby test frameworks
  • Projects that only need unit tests of internal code rather than user-facing behavior
  • Anyone needing WebKit support out of the box, since it is provided only through an external gem
Step-by-step guide: how to use CapybaraInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Ruby 3.0.0 or later · Bundler

    Add the gem to your Gemfile, then install

    gem 'capybara'

    Install dependencies

    bundle install
  2. 2

    Run it

    • Add gem 'capybara' to your Gemfile and run bundle install
    • Require capybara in your test helper (for example capybara/rails for Rails, or capybara/rspec for RSpec)
    • For a Rack app that is not Rails, set Capybara.app to your Rack app
    • Write a feature spec with type: :feature that visits a page and checks for content
  3. 3

    Get the most out of it

    • Tag tests with js: true or a driver option to switch to a browser driver for JavaScript pages
    • Use within to scope actions to a section of the page
    • Configure Capybara.server = :puma to match Rails defaults, as the README suggests
    • Use the Capybara DSL with Cucumber by tagging scenarios @javascript

Downloads

Strengths

  • Readable API that mirrors how a real user interacts with the page
  • Driver can be switched between headless and browser without changing tests, per the README
  • Built-in waiting for asynchronous page changes, so tests need no manual sleeps

Trade-offs

  • JavaScript testing requires a real browser driver such as Selenium, which adds setup
  • WebKit support depends on a separate external gem
  • Requires Ruby 3.0.0 or later

How it compares

ProjectStarsTypeLevelUpdatedBest for
capybara (this)10.2kLibraryintermediate1 months agoRuby and Rails developers writing feature or system tests
cypress51kDev toolbeginner4 days agoDevelopers who want automated browser tests for a web application

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.