Re-running Failed Cucumber Tests

Dec 20, 2020

Cucumber is one of my favourite testing tools and one of the nicer features that it has is the ability to re-run failed tests. To do so,  you can run the following command:

cucumber -f rerun -o rerun.txt

The command will run all of the tests and output all of the failed test into the rerun.txt file in the root of your project. In order to run just the failed test, you would run the following command:

cucumber @rerun.txt

When I first started running the test, I ran into the following error:

cucumber.yml was found, but could not be parsed. Please refer to cucumber's documentation on correct profile usage.

After doing some digging, I found the following Stack Overflow article which resolved the issue for me. The summary for the change is to modify the config/cucumber.yml file with the following line:

rerun = File.file?('rerun.txt') ? IO.read('rerun.txt').gsub(/\n/, ' ') : ""

Tags