Running a cucumber feature multiple times
I'm trying to run a cucumber feature multiple times (i.e 500 times). Is there a way of doing t开发者_开发技巧his than me having to type in the same command everytime? I'm guessing this can be done using Rake? I'm not an expert in using rake or cucumber.
Will appreciate your help.
Thanks
ruby -e '500.times { `cucumber` }'
Within your rake file:
require 'rubygems'
require 'cucumber'
require 'cucumber/rake/task'
cuke_task = Cucumber::Rake::Task.new(:features) do |t|
t.cucumber_opts = "features --format pretty"
end
task :feature, :name, :times do |task,args|
puts "Executing feature: #{args[:name]} #{args[:times]} times"
cuke_task.cucumber_opts = "features/#{args[:name]}"
args[:times].to_i.times { Rake::Task[:features].execute }
end
First I create a default cucumber task that would execute all my features and format them pretty for me.
After that I define a rake task, named feature
that would accept two parameters name
of the feature and times
of execution.
I then augment the cuke task to use the feature name
that I specified and then execute the Rake task the number of times specified.
$ rake feature['login.feature',500]
Tag your feature with something like: @AndIwillwalk500miles
@AndIwillwalk500miles
Feature: Walk A Mile
'That I can walk a mile in another man's shoes.'
Scenario: That I can walk a Mile in loafers
Given I am wearing loafers
And I start at point A
When I walk a mile
Then I am at point B
Create a ruby file in your features/support/
folder. Convention seems to be env.rb
or hooks.rb
, but it doesn't matter what you call it as long as it's in that folder. I call mine env.rb
. Put the following code in it:
Around('@AndIwillwalk500miles') do |scenario, block|
500.times { block.call }
end
When you're done, remove the tag. If you want to run just one scenario from your feature, just tag it instead. This way you can run as many or as few tests as you want 500 times, without needing to use Rake or mess with the command line. This is especially useful if you are moving between operating system environments.
This can also be accomplished using a Scenario Outline and nested steps:
Create a Scenario Outline with N Examples. The scenario will run N times.
Feature: Login Robustness
Scenario Outline: I want to be assured that login works consistently
When i run login # "<login>" repeatedly, it never fails
Examples:
| login |
| repeated login # 1 |
| repeated login # 2 |
| repeated login # N |
…
Utilize your existing steps as nested steps within the scenario outline you define:
When(/^i run login \# "(.*?)" repeatedly, it never fails$/) do |login_run_number|
puts login_run_number
steps %{
Given I am at initial login, Core
When A correct username and password are entered, Native (Core)
Then I should be logged in, Native (Core)
}
end
Advantages:
- Only one report is written for the entire test run; there are not N reports to dig through to see the results.
- It uses existing cucumber functionality; no modifications to the framework are needed.
- Testers already understand how Scenario Outlines work.
Disadvantages:
- Ugly, multiline .feature file.
This is a silly work around, but try this
cucumber features/file.feature features/../features/file.feature
as long as the path to file is not identical each time, you can tack on as many ".." as you want
精彩评论