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!
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.
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.
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.
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.
Capybara.current_driver = :webkit # temporarily select different driver
#... tests ...
Capybara.use_default_driver # switch back to default driver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With