Execute failed Test case in TestNG

In this section we will discuss on Execute failed Test case in TestNG. Failures in execution of the code are genuine and should be handled earliest. But sometimes these failure came because of the following reason.

  • Browser issue and random unresponsiveness of Browsers
  • Random Machine issue
  • Server issue

Though you can fix the failure which occurred through your code but not this type of Failure. To resolve this, you need to run the same test repeatedly until it gets success.

How you will do? Do you need to run the Test class file again by clicking the run icon?

This is one solution but when you will be working with larger number of Test class then this option will be bad and time consuming.

Let’s discuss how we can run the failed Test case automatically through TestNG. 

TestNG provides an awesome feature so that you can retry a test case multiple times before marking as it Failed. That means if you see a failure can just automatically rerun the test to make sure that test is consistently failing. In this way you can reduce the fake failed test case.

In this chapter you will get to know how to retry the failed Test case before marking them as failed.

Execute failed test case in Selenium

Step -1: Check for testing-failed.xml file

Testing-failed.xml file will be created if one or more than one test case will be failed. Once all test case completes the execution this file will be displayed in Suite folder under test-output. see below screenshot.

If you did not find testng-failed.xml file in respective file then refresh the project and check again. This will be displayed.

Step -2: Run the testing-failed.xml file

Once you get the testing-failed.xml file, no need to do anything. Just double  click on the xml file and click on the run.

Once you run the testing-failed.xml file, all the test case which are failed in previous test run will be run again.

From the above discussion, you ave got the clear picture of Execute failed Test case in TestNG

Leave a Reply

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