Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change the testing default driver for a Cucumber test in Capybara?

In the documentation provided by Capybara, you can change the default_driver on a specific test group:

describe 'some stuff which requires js', :js => true do
  it 'will use the default js driver'
  it 'will switch to one specific driver', :driver => :selenium
end

What if I wanted to do this for a specific cucumber test group? How would I add those parameters?

When /^I do something$/  do
  fill_in "a_text_box", :with => "stuff"
  fill_in "another_text_box", :with => "another_thing"
end

Thanks!

like image 444
Goalie Avatar asked May 09 '12 01:05

Goalie


People also ask

What is Capybara cucumber?

cucumber is a BDD tool that expresses testing scenarios in a business-readable, domain-specific language. capybara is an automated testing tool (often used) for ROR applications.

What is Capybara in rails?

Capybara is a web-based test automation software that simulates scenarios for user stories and automates web application testing for behavior-driven software development. It is written in the Ruby programming language.

What is selenium capybara?

Capybara helps you test web applications by simulating how a real user would interact with your app. It is agnostic about the driver running your tests and comes with Rack::Test and Selenium support built in. WebKit is supported through an external gem.


Video Answer


2 Answers

In cucumber, I've done this in two steps:

In /features/support/env.rb, place the following line:

Capybara.javascript_driver = :webkit

Then in the cucumber feature, just before the specific scenario, add @javascript just before the scenario -- like this:

@javascript
Scenario: Successful sign in - with no flash message if using current firefox
When I'm using a current version of Firefox
When I visit the practitioner home page with "[email protected]"'s token
Then I should be signed in as practitioner "Jane Doe"
And I should be on the practitioner activities welcome page
And I should not see a flash message warning me I have an unsupported browser

This tells cucumber to use the javascript driver when it runs that particular scenario.

This is how I've done this using Capybara Webkit -- I'm sure other drivers are similar.

like image 127
Kevin Bedell Avatar answered Oct 05 '22 23:10

Kevin Bedell


Capybara.current_driver = :webkit # temporarily select different driver
#... tests ...
Capybara.use_default_driver       # switch back to default driver
like image 22
DVG Avatar answered Oct 05 '22 22:10

DVG