Has anyone figured out a way to run the same cucumber scenario on multiple browsers/web drivers?


I'm using cucumber + capybara for some web automation testing. I'd love to be able to wire up my own tag (something like @all_browsers before the scenario) and have it run against a list of web drivers I set (celerity, selenium on firefox, ie and chrome). I don't want to have to write the scenario 4 different times with 4 different tags out front. I've looked into trying to do this with a new driver I register via:

Capybara.register_driver :all_browsers do |app|
 # What would even work in here? I don't think anything will.

And then following it up with:

Before('@all_browsers') do
 # Same problem here.

But I'm not quite sure what to put in that Before method that might actually work.

I've tried using cucumber hooks, specifically:

Around('@all_browsers') do |scenario, block|
  Capybara.current_driver = :selenium_firefox

  Capybara.current_driver = :selenium_chrome
  # etc

But this doesn't behave as I had hoped. It uses the same driver and runs the scenario twice with it.

Following along the hook lines, there's this from the cucumber documentation:
You may also provide an AfterConfiguration hook that will be run after Cucumber has been configured. This hook will run only once; after support has been loaded but before features are loaded. You can use this hook to extend Cucumber, for example you could affect how features are loaded...
This may be a potential path to go down for this, but I've not managed to come up with anything that works here either.

I've looked into custom formatters, but they really only look like they do exactly that - format the output, not so much designate how the features are actually run.

I've looked into overriding cucumber's feature runner, but that doesn't look easy or friendly to do.
Help please? Anyone?

By : bergyman


This is possible through the hosted service by SauceLabs. The Cucumber Sauce gem gives you parallel, multi-browser tests.

Alternatively, you may be able to borrow from the source of that gem if you wanted to implement it yourself.

Here is my hack: (my situation is proving a feature works with javascript on and javascript off)

  1. Put each scenario into its own feature file.
  2. Move every line but the last into the 'Background:' section.
  3. Put the last line into a scenario per browser
  4. Tag each scenario appropriately

    Feature: a feature
    Given a user "Jim" exists
    Given a user "Mike" exists
    When I login as "mike"
    And I follow "Lesson 1"
    And I follow "Upload a video"
    Then "#upload_a_video" should be active
    And I fill in "video_title" with "my film"
    And I attach the file "video.mov" to "video_upload"
    And I press "Post"
    Scenario: normal
    And I should see "my film"
    Scenario: javascript
    And I should see "my film"

This video can help you solving your question :)
By: admin