Extent Reports version 3.0.2 - AppendExisting

2019-08-17 17:36发布

Below is the code I am trying to use to append all tests to a single report. However, latest test is replacing all the older test reports. So, it's not appending to a single report for some reason. Can you please help me out here?

var htmlReporter = new ExtentHtmlReporter(ResourcesConfig.ReportPath);
            extent = new ExtentReports();
            extent.AttachReporter(htmlReporter);
            htmlReporter.LoadConfig(ResourcesConfig.ReportXMLPath);
            **htmlReporter.AppendExisting = true;**

1条回答
唯我独甜
2楼-- · 2019-08-17 17:48

I had a lot of trouble with this as well as the documentation doesn't explain much. I have one method called ReportCreation which runs for every test case and in that method i have the following:

public static ExtentReports ReportCreation(){
    System.out.println(extent);
    if (extent == null) {
        extent = new ExtentReports();
        htmlReports = new ExtentHtmlReporter(fileName+ n + "\\extentReportFile.html");
        htmlReports.config().setReportName("Pre release Smoke test");
        htmlReports.config().setTheme(Theme.STANDARD);
        htmlReports.config().setTestViewChartLocation(ChartLocation.BOTTOM);
        extent.attachReporter(htmlReports);
    }
    else {
        htmlReports = new ExtentHtmlReporter(fileName+ n+ "\\extentReportFile.html");
        htmlReports.setAppendExisting(true);
        extent.attachReporter(htmlReports);
    }
    return extent;
}

So when the first unit test is run, it will create the html report, but the second unit test will see that the report has already been generated and so use the existing one.

I have created a random number generator so that it goes to a different report on every run

public static Random rand = new Random();
    public static int n = rand.nextInt(10000)+1;
查看更多
登录 后发表回答