I am trying to save an Extent report into a folder on my C:/drive. Currently it is just saving the report into the project folder.
I've tried different paths and making sure I give access to the java folder.
This is the class where the reporter gets attached and also the file path gets set.
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;
}
}
I expect it to save the report into my documents. The actual result is the report gets saved in the project folder.
Correction in yours:
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");
}