Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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; // set your count to re-run test
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(retry.getClass());
			testannotation.setRetryAnalyzer(RetryAnalyzer.class);
		}

	}
	//public void transform(ITestAnnotation testannotation, Class arg1, Constructor arg2, Method arg3) {
		// TODO Auto-generated method stub
		
	

}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900