Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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); 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...