anshooarora / extentreports-java

Community version of Extent API for Java has moved to https://github.com/extent-framework/
http://extentreports.com
Other
528 stars 318 forks source link

Test case status appears to be fail, if i removeTestCase that was fail in first attempt but gets passed in second retry #1058

Open QuasarsResources opened 6 years ago

QuasarsResources commented 6 years ago

public class ExtentReport { public static ExtentHtmlReporter htmlReporter; public static ExtentReports extent; public static ExtentTest deviceNameInReport; public static ExtentTest testCase;

Logger logger = LoggerFactory.getLogger(ExtentReport.class);

public void startReport() {
    logger.info("\t\tInitializing Extent Report         ");
    htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") + "/ExtentReport.html");
    extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    extent.setSystemInfo("Host Name", "Quasars Project");
    extent.setSystemInfo("Environment", "Continuous Regression");
    extent.setSystemInfo("User Name", "Quasars);

    htmlReporter.config().setDocumentTitle("Quasars Automation");
    htmlReporter.config().setReportName("Quasars Test Automation Report");
    htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
    htmlReporter.config().setTheme(Theme.STANDARD);
}

public static void startTestCase(String testCaseName) {
    testCase = deviceNameInReport.createNode(testCaseName);
}

public static void endTestCase() {
    extent.flush();
}

}


public class Retry implements IRetryAnalyzer { private int retryCount = 0; private int maxRetryCount = 2;

// Below method returns 'true' if the test method has to be retried else 'false'
// and it takes the 'Result' as parameter of the test method that just ran
public boolean retry(ITestResult result) {

    if (retryCount < maxRetryCount) {
        ExtentReport.extent.removeTest(ExtentReport.testCase); // DELETING RETRY CASES FROM THE REPORT
screen shot 2018-04-11 at 11 16 40 am
        System.out.println("Retrying test " + result.getName() + " with status "
                + getResultStatusName(result.getStatus()) + " for the " + (retryCount + 1) + " time(s).");
        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;
}

}

anshooarora commented 6 years ago

I am unable to reproduce. Can you share a small snippet or project that I can use to reproduce?