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