We have seen an example to Re-run failed tests using iRetryListener. In the previous example, the count of the tests run was changing based on the maxRetryCountvalue. To over come that, we need to add the below code snippet for onFinish method by implementing 'ITestListener'
Re-Run Failed Tests
There may be many reasons for a Test case getting failed, may be due to element not found or time out exception or stale element exception etc. Normally in automation after executing scripts/tests, we will check for the results and if the test fails because of above reasons we will re-run then again.
Instead of that we can ask testNG to execute the failed test cases again for X (we can define) number of times and check for the updated results.