You can use the IRetryAnalyzer interface provided by for this. Using this you can retry your multiple times till it passes. In the below example Ithe max retry count is set to 1.

public class Retry implements IRetryAnalyzer{


    int retryCount =0;

    int maxRetryCount = 1;


    public boolean retry(ITestResult result) {

        // TODO Auto-generated method stub

        if(retryCount < maxRetryCount){

                System.out.println("Retrying test with "+result.getName()+" with status "+

                        getResultStatusName(result.getStatus()));

                retryCount++;

                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;

    }




}


public class RetryListner implements IAnnotationTransformer{


    public void transform(ITestAnnotation annotation, Class testClass,

            Constructor testConstructor, Method testMethod) {

        // TODO Auto-generated method stub

        IRetryAnalyzer analyzer = annotation.getRetryAnalyzer();


        if(analyzer ==null){

            annotation.setRetryAnalyzer(Retry.class);

        }

    }




}

And add the listener to the testng.xml

<listener 

     class-name="com.listeners.RetryListner">

        </listener> 



Source link https://sqa.stackexchange.com/questions/15329/-failed-test-cases-in-testng

LEAVE A REPLY

Please enter your comment!
Please enter your name here