本文介绍了范围报告 3.0.2 版 - AppendExisting的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我试图用来将所有测试附加到单个报告的代码.然而,最新的测试正在取代所有旧的测试报告.因此,出于某种原因,它不会附加到单个报告中.你能帮我一下吗?

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;**

推荐答案

我在这方面遇到了很多麻烦,而且文档也没有解释太多.我有一个名为 ReportCreation 的方法,它为每个测试用例运行,在该方法中我有以下内容:

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;
}

所以当第一个单元测试运行时,它会创建 html 报告,但第二个单元测试会看到报告已经生成,所以使用现有的.

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;

这篇关于范围报告 3.0.2 版 - AppendExisting的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 13:11