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