Automatically Re-Running Failed Scenarios in Cucumber- Junit


Automatically Re-Running Failed Scenarios in Cucumber- Junit

In this post, we are going to learn how to Rerun our failed scenario in Cucumber-Junit Testing Framework.

Step 1: In Runner File inside plugin we need to write “rerun:rerun/failed_scenarios.txt”. Cucumber will write the failed scenario and line number in the generated failed_scenarios.txt file.



Step 2: We Need to Create another Runner File. Let’s Name it as ReRunRunner.Java and inside feature we need to provide the name of this failed_scenario.txt file along with @.


Now once any of our scenarios will get failed this failed_scenarios.txt the file will be generated inside the rerun folder with failed feature file name and using the ReRunner.Java file created in Step 2 we can easily rerun our failed scenario in Cucumber-Junit.






SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post
May 15, 2019 at 3:41 PM

There are some problem in this code such as:
1. The scenario name it is not mentioning in the . txt file.
2. After Rerun the file is not getting deleted even if the scenarios got pass after Rerun.
3. It's not getting executed automatically. We need to manually run the rerun. Java file to get it executed.
Please suggest if you have any solutions to the above.

Reply
avatar
May 15, 2019 at 9:26 PM

Hi Ranjan,
1) scenarios names are getting displayed in .txt file I have also attached screenshot for that.

2) This functionality is built in the same line as testng-failed.xml file.This is something I can't control.

3) The purpose of this blog is to showcase how to automatically get the list of failed scenario again this is in line with TestNg architecture.

For automtocally rerunning this there is another article on the blog which you can refer.

Reply
avatar
July 4, 2019 at 12:07 PM

can you share the .txt file and let me know where it would be added...
Thanks
Sumanth

Reply
avatar