How to choose default driver in Capybara?

Capybara uses the same DSL to drive a variety of browser and headless drivers. The default drivers for Capybara is RACK WebDriver.

Common Capybara WebDrivers

1. RACK (default)
2. Selenium
3. Capybara-webKit
4. Poltergeist (headless)

Syntax for selecting drivers

Capybara.default_driver = :[driver name]


Capybara.default_driver = :rack_test
Capybara.default_driver = :selenium

You can change the default driver in any time on the execution using following code:

Capybara.current_driver = :webkit

after execution of the block, you can again switch back to default driver using following code:


Sample Program

require 'capybara/cucumber'
Capybara.default_driver = :selenium     # choosing driver

Given (/^I have access to website$/) do
visit ""

Capybara.current_driver =:webkit    # switched to webkit driver

Then (/^I should see title$/) do

Capybara.use_default_driver         # switching back to default driver i.e selenium

One thought on “How to choose default driver in Capybara?

  1. RMAU says:

    If you are using a SQL database, it is common to run every test in a transaction, which is rolled back at the end of the test, rspec-rails does this by default out of the box for example. Since transactions are usually not shared across threads, this will cause data you have put into the database in your test code to be invisible to Capybara.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.