Hi,
I have implemented two classes( RetryListener and Analyzer) in order
to reexecute a failed test twice. From this perspective it works fine
but I am facing the following problem:
I want to have the first test result as skipped.For this reason in
Analyzer class I had set arg0.setStatus(ITestResult.SKIP);
Nevertheless I always take the result as fail.
I also observed that the following annotation combination @Test
(priority=0,successPercentage=50,retryAnalyzer=Analyzer.class) does
not work in the concept that if that test methods executes twice, the
first time is failed and the second is passed I always take 1 passed
and 1 failed test.In the same scenarion if I use the combination
@Test (priority=0,successPercentage=50,invocationCount = 2) I take1
passed test. So it seems that there is some problem in the
IRetryAnalyzer .From what I have seen this problem with the results is
a known issue. Any idea why this happens? Should it be a fix for that
issue? I am using the latest testng (6.0.1)
Thank you in advance
Panagiotis
@Test (priority=0,successPercentage=50,retryAnalyzer=Analyzer.class)
public void test2() throws InterruptedException
{
System.out.println("\n\n");
System.out.println("I am the second\n");
Thread.sleep(2000);
SuperHelper.noWindowLoaded = true;
// if(SuperHelper.invocationsCount == 0)
Reporter.log("<font color=\"#FF00FF\"/>"+message+"</font><br>\n");
test++;
if(test==1)
throw new InterruptedException();
}
package com.helper;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import org.testng.IAnnotationTransformer;
import org.testng.IRetryAnalyzer;
import org.testng.annotations.ITestAnnotation;
public class RetryListener implements IAnnotationTransformer {
@SuppressWarnings("unchecked")
@Override
public void transform(ITestAnnotation arg0, Class arg1, Constructor
arg2,Method arg3) {
IRetryAnalyzer retry = arg0.getRetryAnalyzer();
if (retry==null){
arg0.setRetryAnalyzer(Analyzer.class);
}
}
}
package com.helper;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
import com.Seleniumhelper.SeleniumWebdriver;
public class Analyzer implements IRetryAnalyzer {
public static int MAX_RETRY_COUNT = 1;
private int count = 0;
String message = "First failure,the test will be executed once more";
@Override
public boolean retry(ITestResult arg0) {
count++;
if(count <= MAX_RETRY_COUNT && SuperHelper.noWindowLoaded ){
arg0.setStatus(ITestResult.SKIP);
SeleniumWebdriver.LOGGER.info("\t"+message);
SuperHelper.noWindowLoaded = false;
return true;
}
return false;
}
}