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]

example:

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:

Capybara.use_default_driver

Sample Program

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

Given (/^I have access to website$/) do
visit "http://aravin.net"
end

Capybara.current_driver =:webkit    # switched to webkit driver

Then (/^I should see title$/) do
page.find('.site-title')
end


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.