I am using dataprovider method and a test method (with ITestContext parameter in the test method). A simplified example is as follows :
@DataProvider(name="Dataprovider")
public Object[][] dataprovider(){
return new Object[][]{{1},{2,},{3}};
}
@Test(dataProvider="Dataprovider")
public void test(int data, ITestContext itx){
System.out.println(data);
org.testng.Assert.assertEquals(data, 3);
}
My Retry class and RetryListener classes are below :
public class RetryListener implements IAnnotationTransformer {
@Override
public void transform(ITestAnnotation testannotation, Class testClass,
Constructor testConstructor, Method testMethod) {
IRetryAnalyzer retry = testannotation.getRetryAnalyzer();
if (retry == null) {
testannotation.setRetryAnalyzer(Retry.class);
}
}
}
public class Retry implements IRetryAnalyzer {
private static int retryCount = 0;
private int maxRetryCount = 1;
// Below method returns 'true' if the test method has to be retried else 'false'
//and it takes the 'Result' as parameter of the test method that just ran
public boolean retry(ITestResult result) {
if (retryCount < maxRetryCount) {
System.out.println("Retrying test " + result.getName() + " with status "
+ getResultStatusName(result.getStatus()) + " for the " + (retryCount+1) + " time(s).");
retryCount++;
return true;
}
retryCount = 0;
return false;
}
public String getResultStatusName(int status) {
String resultName = null;
if(status==1)
resultName = "SUCCESS";
if(status==2)
resultName = "FAILURE";
if(status==3)
resultName = "SKIP";
return resultName;
}
}
Expected : When test fails, the retry is called by TestNG, then the dataprovider should return the same values to the test method.
Observed : Dataprovider returns the same value but test method doesn't run and the retry terminates and next test starts (new values will now be returned by dataprovider)
But my retry does not enter the test method ( It is not expecting the (int data, ITestContext itx) for test method). If I remove ITestContext, the retry works.
ITestContext is a must for maintaining the test case context. So how to perform retry along with keeping the ITestContext in the test method.
ITestContext itx
. – Grzegorz Górkiewicz