2

How to execute only the specific failed tests. By using 'IRetryAnalyzer' we can re-run the failed tests for x number of time. As mentioned here Restart failed test case automatically. I have also implemented iTestListener to make the tests count more meaning full by following Retry Only failed Tests and update test run count by implementing 'ITestListener'

Is there any way to Re-run ONLY specific failed tests.

Example: We need to execute only tests which are failed because of NoSuchElementException and TimeoutException.

Please find the below screen shot where total 8 tests are failed and there are 6 tests which are failed because of NoSuchElementException-1 and TimeoutException-5. enter image description here

Please help.

Community
  • 1
  • 1
Dev Raj
  • 650
  • 2
  • 7
  • 18

1 Answers1

5

You can try out by checking the result of your tests like:

@Override
public boolean retry(ITestResult result) {
try {
    if (result.getThrowable().toString()
        .contains("NoSuchElementException")) // Checking for specific reasons of failure
        if (retryCount < maxRetryCount) {
            retryCount++;
            return true;
        }
    return false;
    } catch (Exception e) {
        return false;
    }
}

Since every result has an attribute m_throwable in case of exception has occurred, you can use it to get your task done in Retry class.

Vivek Singh
  • 3,641
  • 2
  • 22
  • 27