问题
I have an ExtentReports API implemented into my Java code in my Selenium - Web Automation project.
What ExtentReports does is, After running the code it produces a report. Currently it saves the created file on my project folder.
I would like to save the reports on a specific directory, and not using "user.dir".
For example I would like to save it on C:\Reports How would I do that?
Here is my currently working code for saving :
System.getProperty("user.dir") + "/test-outputExtentReports/STMExtentReport" + currTimeDate + ".html", true);
extent.loadConfig(new File(System.getProperty("user.dir") + "\\src\\extentReports\\extent-config.xml"));
Please help with the given directory above. Thanks
回答1:
Below is an example of where I create the report, modified to reflect placing it in the C:\Reports folder, as you request:
ExtentHtmlReporter htmlReporter;
ExtentReports extent;
ExtentTest test;
String storyName = this.getClass().getSimpleName();
String storyDesc = "Calculator Test Story";
// start reporters
htmlReporter = new ExtentHtmlReporter("C:\\Reports\\" + storyName + ".html");
// create ExtentReports and attach reporter(s)
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
// creates a toggle for the given test, adds all log events under it
test = extent.createTest(storyName, storyDesc);
回答2:
What user.dir does is it initiates the system path. If you don't won't to use system path you can just initiate the absolute path.
Refer the sample code below:
String extentReportFile = "U:\\Reports\\"+reportName+".html";
ExtentReports extent= new ExtentReports(extentReportFile, false);
NOTE : The "U:\\Reports" is the absolute location where you want to store your reports.
来源:https://stackoverflow.com/questions/49029527/how-to-save-a-file-extentreports-report-in-my-case-or-any-other-file-in-a-sp