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

In the documentation provided by Capybara , you can change default_driver in 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 want to do this for a specific cucumber testing group? How to add these parameters?

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

Thanks!

+8
ruby-on-rails cucumber capybara
source share
3 answers

In the cucumber, I did this in two stages:

In /features/support/env.rb put the following line:

 Capybara.javascript_driver = :webkit 

Then, in the cucumber function, immediately before the specific script, add @javascript just before the script - for example:

 @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 "jane.doe@example.com" 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 the cucumber to use the javascript driver when it runs this particular script.

Here's how I did it with Capybara Webkit - I'm sure the other drivers are similar.

+5
source share
 Capybara.current_driver = :webkit # temporarily select different driver #... tests ... Capybara.use_default_driver # switch back to default driver 
+4
source share

With cucumber, you can achieve this with tags. For example, if your default driver is webkit, but you want to run some script using selenium, you can mark it with @selenium . This works with gem 'selenium-webdriver' by default

In general, if you want to switch to some other driver (without it, chrome in this example), put the following code in features/support/drivers.rb :

 # features/support/drivers.rb Around '@headless_chrome' do |scenario, block| begin Capybara.current_driver = :headless_chrome # temporarily select headless chrome block.call ensure Capybara.use_default_driver # switch back to default webkit driver end end 
0
source share

All Articles