扩展数据块 HTML 报表未保存在正确的位置



我正在尝试将范围报告保存到 C:/drive 上的文件夹中。目前,它只是将报告保存到项目文件夹中。

我尝试了不同的路径,并确保我可以访问java文件夹。

这是附加报告器的类,也是设置文件路径的类。

class ExtentManager {
    private static ExtentReports extent;
    private static String fileName = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date());
    static ExtentReports getInstance() {
        if (extent == null) {
            extent = createInstance("Testing " + fileName + ".html");
            System.out.println("JUST CREATED A NEW EXTENT");
        }
        return extent;
    }
    private static ExtentReports createInstance(String fileName) {
        ExtentHtmlReporter htmlReporter = new ExtentHtmlReporter(fileName);
        htmlReporter.config().setTestViewChartLocation(ChartLocation.BOTTOM);
        htmlReporter.config().setChartVisibilityOnOpen(true);
        htmlReporter.config().setTheme(Theme.DARK);
        htmlReporter.config().setDocumentTitle(fileName);
        htmlReporter.config().setEncoding("utf-8");
        htmlReporter.config().setReportName(fileName);
        htmlReporter.config().setFilePath(System.getProperty("user.home") + ("/Documents/ExtentReport/HTMLReports"));
        ExtentReports extent = new ExtentReports();
        extent.attachReporter(htmlReporter);
        return extent;
    }
}

我希望它将报告保存到我的文档中。实际结果是报告保存在项目文件夹中。

更正你的:

  private static String fileName = new SimpleDateFormat("yyyy-MM-dd-HH-mm").format(new Date());
  String reportLocation = "C:/ReportFolder/" + "Testing " + fileName + ".html";
  static ExtentReports getInstance() {
    if (extent == null) {
        extent = createInstance(reportLocation);
        System.out.println("JUST CREATED A NEW EXTENT");
    }

最新更新