I'm looking for a solution to execute failed test cases automatically on Jenkins. I'm currently running test cases through pom.xml which points to testng.xml

I'm using extent reports to capture and display test results which are located at this location on my workspace /ws/Resources/reports.html. Is there a way to just execute failed test cases based on extent report? and store the results in a new report.

I tried looking into testng-failed.xml solution but I don't think it actually captures the correct failed @Test methods, at least not in my case.

For every Test, I'm using extent report "Result.log(LogStatus.FAIL,"test case name")" in the catch block to mark a test case as failed so perhaps need something to read the test case name and execute it if it failed?

Any help would be greatly appreciated


2 Answers 2


you can execute using testng not extendreport. There will be a testng-failed.xml getting created at "test-output" folder you can use this to rerun code.

you can run scripts from java as :

    // Create object of TestNG Class
    TestNG testng = new TestNG();

    // Create a list of String
    List<String> suitefiles = new ArrayList<String>();

    // Add xml file which you have to execute

    // now set xml file for execution

    // finally execute the runner using run method

This will have all required listneres . You can also implement Iretryanazlyzer to rerun testng


In software testing service you can achieve this using multiple ways. One of the way is as follow.

Write a code in your class that implement 'IRetryAnalyzer' just as below.

package com.mavericks.qa.RetryListener;

import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;
public class RetryFailedTestCases implements IRetryAnalyzer {
    private int retryCnt = 0;
    //You could mentioned maxRetryCnt (Maximiun Retry Count) as per your requirement. Here I took 2, If any failed testcases then it runs two times
    private int maxRetryCnt = 2;
    //This method will be called everytime a test fails. It will return TRUE if a test fails and need to be retried, else it returns FALSE
    public boolean retry(ITestResult result) {
        if (retryCnt < maxRetryCnt) {
            System.out.println("Retrying " + result.getName() + " again and the count is " + (retryCnt+1));
            return true;
        return false;

And another file 'RetryListenerClass' having code like as below

package com.mavericks.qa.RetryListener;

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 RetryListenerClass implements IAnnotationTransformer {

    public void transform(ITestAnnotation testannotation, Class testClass, Constructor testConstructor, Method testMethod)  {
        IRetryAnalyzer retry = testannotation.getRetryAnalyzer();

        if (retry == null)  {


Now just add below lines in your testng file before the test Extent listner

            class-name="com.mavericks.qa.RetryListener.RetryListenerClass" />

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.