'Extent test report V3 (junit4) - Troubleshoot with appending test cases under 1 class into unique report
I have problem with appending tests into a test report. I just wanted to do the most basic steps, so I wrote 4 tc. When I run them and open the report, every time they are duplicated in the report.
I am using extent report version 3 and Junit4 and I was following the documentation from their website.
For appending test cases I am using command htmlReporter.setAppendExisting(true);.
This is my code:
    public class ExtentReport3 {
@Test
    public void OpenaAccount() throws Exception{
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("./src/TestExtent3.html");
    htmlReporter.setAppendExisting(true);
    // create ExtentReports and attach reporter(s)
    ExtentReports extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    // creates a toggle for the given test, adds all log events under it
    ExtentTest test = extent.createTest("4.Open account test", "Sample description");
    // log(Status, details)
    test.log(Status.INFO, "Step 1");
    test.log(Status.INFO, "Step 2");
    extent.flush();
}
@Test
public void LoginForm () throws Exception{
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("./src/TestExtent3.html");
    htmlReporter.setAppendExisting(true);
    // create ExtentReports and attach reporter(s)
    ExtentReports extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    // creates a toggle for the given test, adds all log events under it
    ExtentTest test1 = extent.createTest("3.Login form", "Sample description");
    // log(Status, details)
    test1.log(Status.INFO, "Step 1");
    test1.log(Status.INFO, "Step 2");
    extent.flush();
}
@Test
public void CheckOutForm() throws Exception{
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("./src/TestExtent3.html");
    htmlReporter.setAppendExisting(true);
    // create ExtentReports and attach reporter(s)
    ExtentReports extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    // creates a toggle for the given test, adds all log events under it
    ExtentTest test2 = extent.createTest("1.Checkout form", "Sample description");
    // log(Status, details)
    test2.log(Status.INFO, "Step 1");
    test2.log(Status.INFO, "Step 2");
    extent.flush();
}
@Test
    public void CancelOredr() throws Exception{
    ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter("./src/TestExtent3.html");
    htmlReporter.setAppendExisting(true);
    // create ExtentReports and attach reporter(s)
    ExtentReports extent = new ExtentReports();
    extent.attachReporter(htmlReporter);
    // creates a toggle for the given test, adds all log events under it
    ExtentTest test3 = extent.createTest("2.Cancel order", "Sample description");
    // log(Status, details)
    test3.log(Status.INFO, "Step 1");
    test3.log(Status.INFO, "Step 2");
    extent.flush();
  
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
