Selecting the Driver

Selecting the Driver

Selecting the Driver

Let’s stand and understand Selecting the Driver. By default, Capybara uses the :rack_test driver, which is fast but limited: it does not support JavaScript, nor is it able to access HTTP resources outside of your Rack application, such as remote APIs and OAuth services. To get around these limitations, you can set up a different default driver for your features. For example if you’d prefer to run everything in Selenium, you could do:

Capybara.default_driver = :selenium

However, if you are using RSpec or Cucumber, you may instead want to consider leaving the faster :rack_test as the default_driver, and marking only those tests that require a JavaScript-capable driver using :js => true or @javascript, respectively. Not to mention, JavaScript tests run using the :selenium driver. You can change this by setting Capybara.javascript_driver.

You can also change the driver temporarily (typically in the Before/setup and After/teardown blocks):

Capybara.current_driver = :webkit # temporarily select different driver

# tests here

Capybara.use_default_driver       # switch back to default driver

switching the driver creates a new session, so you may not be able to switch in the middle of a test.

Make your resume stand out and become a Certified Capybara Testing Professional. Try free practice tests here!

A great career is just a certification away. So, practice and validate your skills to become Certified Capybara Testing Professional

Using Capybara with MiniTest::Spec
RackTest

Get industry recognized certification – Contact us

keyboard_arrow_up