Hi All,
I am using TestNG 6.9.10 and facing some issue's with IAnnotationTransformer & IRetryAnalyzer interface's while implementing Retry logic for false failure.
1. Issue is : Suppose I want to retry failed test case two times, While execution its shows like Skip in First & second attempt & then fail.
But at last its show something like :
Run 1: PASS
Run 2: PASS
Run 3:
********VerifyRateTableHas20Records:Intentionally fail!!!!!!!!! expected [true] but found [false]
and same thing has also been updated in reports as well.
Can someone please help me out???
My Code :
public class AnnotationTransformer implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
annotation.setRetryAnalyzer(Retry.class);
}
}
public class Retry implements IRetryAnalyzer {
private int count = 0;
private static int maxTry = 3;
@Override
public boolean retry(ITestResult iTestResult) {
if (!iTestResult.isSuccess()) { //Check if test not succeed
if (count < maxTry) { //Check if maxtry count is reached
count++; //Increase the maxTry count by 1
iTestResult.setStatus(ITestResult.FAILURE); //Mark test as failed
return true; //Tells TestNG to re-run the test
} else {
iTestResult.setStatus(ITestResult.FAILURE); //If maxCount reached,test marked as failed
}
} else {
iTestResult.setStatus(ITestResult.SUCCESS); //If test passes, TestNG marks it as passed
}
return false;