Executing Failed TestCases in Selenium using TestNG

We want to re-run only the failed testcases in selenium, rather than running the entire suite.

Every time tests fail in a suite, TestNG creates a file called testng-failed.xml in the output directory. This XML file contains the necessary information to rerun only these methods that failed, utlizing this we can easily rerun the failed tests without having to run the entire test suite.

Note:- For running the test exactly after the failure we need to call the method that failed. We can get that method name from  IRetryAnalyzer interface . If we just want to rerun all the failed test cases together, then we can give the testng-failed.xml as input xml after the first execution.But remember this will result in creation of 2 reports, one of previous run + latest run of the failed test cases, rather than having the consolidated report

Locate the testng-failed.xml file

rerrun failed tests in selenium
opening testng-failed

Rerun this file to execute only the failed test cases.
(Open file -> CTRL+F11)

testng-failed.xml file
testng-failed.xml file view

How to run parallel Selenium Tests


Leave a Reply

Your email address will not be published. Required fields are marked *