Hi,
I am currently working with a test automation framework. I have a test suite contains different a number of test, which have different methods. I have to find out a way to re-run the complete test if any of the methods in that test fails.
for e.g.
<test name="TestFrw_TC24(1)">
<parameter name="InputExcelPath" value="TestFrw_TC24(1).xls" />
<parameter name="myUsername" value="TestFrwagent1" />
<parameter name="myPassword" value="TestFrwagent1" />
<classes>
<class name="com.TestFrw.testcases.transactions.Mainflow">
<methods>
<include name="testLogin" />
<include name="testSearch" />
<include name="testSummary" />
<include name="testWithdraw" />
</methods>
</class>
</classes>
</test>
if "testSearch" method failed once, I want to execute the entire test again(from testlogin to testWithdraw)
please help me to find a solution to repeat the entire test if any of the methods are failed. I am using java for coding.
What I have tried:
I have used RetryAnalyzer and RetryListner. But it repeats the execution of only the failed method.
My RetryAnalyzer classis as follows.
package com.TestFrw.utilities;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class RetryAnalyzer implements IRetryAnalyzer {
private int count = 0;
private int maxCount = 4;
protected Logger log;
private static Logger testbaseLog;
static {
PropertyConfigurator.configure("test-config/log4j.properties");
testbaseLog = Logger.getLogger("TestclassName");
}
public RetryAnalyzer()
{
testbaseLog.trace( " ModeledRetryAnalyzer constructor " + this.getClass().getName() );
log = Logger.getLogger("TestclassName");
}
@Override
public boolean retry(ITestResult result) {
testbaseLog.trace("running retry logic for '"
+ result.getName()
+ "' on class " + this.getClass().getName() );
if(count < maxCount) {
count++;
System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"+"Retrying test " + result.getName() + " with status "
+ getResultStatusName(result.getStatus()) + " for the " + (count+1) + " time(s).");
return true;
}
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;
}
}
My RetryListner class is as folows.
package com.TestFrw.utilities;
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 {
@Override
public void transform(ITestAnnotation testannotation, Class testClass,
Constructor testConstructor, Method testMethod) {
IRetryAnalyzer retry = testannotation.getRetryAnalyzer();
if (retry == null) {
testannotation.setRetryAnalyzer(RetryAnalyzer.class);
}
}
}