Parallelising Cucumber
The ‘parallel_test‘ is a awesome rubygem to speedup your Rspec, Cucumber and Test Unit scenarios. Parallel _test also allows us to run Cucumber into different process and speedup the entire execution. In my previous blog post ‘speed up BDD with parallel cucumber‘ we have seen the basic setup of parallel-test, scenario execution and reports aggregation.
In this post, we will see how to handle flacky scenarios by re-running them with parallel cucumber.
Source Code
Source Code of this demo is available on GitHub ‘ parallel-cucumber-failed-rerun‘
https://github.com/Shashikant86/parallel-cucumber-failed-rerun
Setup
Inside cucumber.yml
if you got existing project add this to your cucumber.yml report logger as a new profile
1 |
parallel: --format ParallelTests::Cucumber::FailuresLogger --out cucumber_failures.log |
This will created ‘cucumber_failures.log’ with all failed scenario which we can use it for rerunning.
You can also add another profile to generate html reports of each cucumber process.
1 |
html: --format html --out reports/process<%= ENV['TEST_ENV_NUMBER'] %>.html |
Run features in parallel
Now, you can run your features in parallel using that profile
1 |
$ bundle exec parallel_cucumber features/ -n 10 -o "-p parallel" |
This will run your entire features into 10 different processes and logs failed scenarios in the ‘cucumber_failures.log’ file.
Re-run failed features
Now that, we got ‘cucumber_failures.log’ file with all failed scenarios. We can use that file to re-run failed cucumber scenarios. like this
1 |
bundle exec cucumber @cucumber_failures.log -f pretty |
Rakefile
You can put all things into one Rakefile i.e deleting reports, running in a parallel and re-running failed scenarios.
Rakefile has 4 different tasks to perform different cucumber operations
cleanup
This task delete old html reports and cucumber failures log file and create new one for fresh execution.
parallel_cucumber
This task runs features in parallel and create ‘cucumber_failures.log’ file with failed scenarios.
rerun
This task will rerurn only failed scenarios.
test
This task will combine everything in one.
Using Demo Project
You can start from simple demo on Github
1 2 3 4 |
$ git clone https://github.com/Shashikant86/parallel-cucumber-failed-rerun $ cd parallel-cucumber-failed-rerun $ bundle install $ bundle exec rake test |
You can watch video demo on Youtube here