我正在尝试为运行TestNG XML时所生成的scopeReport生成一个动态名称,
例如,如果我正在运行的testSuite命名为“ SmokeTests”,则报告应为SmokeTests.html
我非常感谢您的帮助。 我正在使用以下代码:
package com.herokuapp.theinternet.extentReports;
import com.aventstack.extentreports.ExtentReports;
import com.aventstack.extentreports.reporter.ExtentSparkReporter;
import com.aventstack.extentreports.reporter.configuration.Theme;
import com.herokuapp.theinternet.base.TestUtilities;
import org.testng.ITestContext;
import org.testng.annotations.BeforeClass;
import java.io.File;
import java.util.Date;
public class ExtentManager extends TestUtilities {
private static ExtentReports extent;
public static String testSuite;
public static ExtentReports createInstance() {
String fileName = getReportName();
String directory = System.getProperty("user.dir") + "/test-output/" + "/extentReports/" + getTodaysDate() + File.separator;
/*+ File.separator + "test-output"
+ File.separator + "extentReports" + File.separator + getTodaysDate();*/
new File(directory).mkdirs();
String path = directory + testSuite;
ExtentSparkReporter htmlReporter = new ExtentSparkReporter(path);
/** configuring and setting up the Extent Report */
htmlReporter.config().setEncoding("utf-8");
htmlReporter.config().setDocumentTitle("Automation reports");
htmlReporter.config().setReportName("Automation Test Results");
htmlReporter.config().setTheme(Theme.STANDARD);
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
return extent;
}
public static String getReportName() {
Date d = new Date();
String fileName = "";
// " AutomationReport" + ".html";
// //+ "_" + d.toString().replace(":", "_").replace(" ", "_")
return fileName;
}
@BeforeClass
public static void getTestSuite(ITestContext ctx) {
testSuite = ctx.getSuite().getName();
}
}