How to save a file (ExtentReports report in my case, or any other file), in a specific directory chosen by me?

蹲街弑〆低调 提交于 2019-12-14 03:34:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!