Pages

Wednesday, 12 August 2020

How to rerun only failed test cases using testng in automation testing framework? TestNG listeners for Automation Framework



 

 

 

 

 

 

1. Create a class which implements IRetryAnalyzer and provide the retry count @maxRetryCount

public class FailRetry implements IRetryAnalyzer {
 
  private int retryCount = 0;
  private static final int maxRetryCount = 2;
 
  @Override
  public boolean retry(ITestResult result) {
    if (retryCount < maxRetryCount) {
      retryCount++;
      return true;
    }
    return false;
  }
  }
 
2. Create a class which implements IAnnotationTransformer and pass the class name that we have created in step-1  @setRetryAnalyzer

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(FailRetry.class);//pass the class name created in Step-1
        }

    }
}

3. Add listener in testng.xml file after the suite tag as below and define the class name created in Step-2 with the package path

<suite name="Automation Test Suite for IX Onespace">
<listeners>
        <listener class-name="com.task.automation.util.RetryListener"/>
  </listeners>

Need more Framework Design related code: Check out below post==>https://automationreinvented.blogspot.com/search/label/FrameworkDesign

 TestNG related interview questions for SDET:
https://automationreinvented.blogspot.com/search/label/TestNG

 JAVA related posts:
https://automationreinvented.blogspot.com/search/label/Java

QA Job Opening: Click here


************************************************* 

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design 
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions

No comments:

Post a Comment