3

Hello I'm having a slight issue. I'm using selenium to make a report through ExtentReport which saves a HTML file. I want to be able to save this file dynamically.

This is the code im currently using.

report = new ExtentReports("/Users/xxxx/Desktop/ExtentReport/ExtentReport.html" + System.currentTimeMillis());

Adding System.CurrentTimeMills kind of works as it saves it but it ends up being ExtentReport.html1919191919191919191 which works.

The problem that I have is that after I run my selenium test I want it to navigate to the folder and open the HTML as soon as the test is over.

If I use currentTime then I can't open the file as it is made and called about a minute inbetween giving different file names.

This is the code I use to call it after the test is over.

String Path ="file:/Users/xxxxx/Desktop/ExtentReport/ExtentReport.html" + System.currentTimeMillis();
driver.get(Path);

How can I save my html file dynamically whilst still being able to call it later on during my script to open?

1 Answer 1

5

Save the filename as a variable. Then pass the variable to the constructor, and also pass it to whatever code needs to open the file later.

String reportFileName = "/Users/xxxx/Desktop/ExtentReport/ExtentReport.html" + System.currentTimeMillis());

report = new ExtentReports(reportFileName);

...

Also, it might be better to put the timestamp before the extension:

String reportFileName = "/Users/xxxx/Desktop/ExtentReport/ExtentReport" + System.currentTimeMillis()) + ".html";

That way, if you want to open the file with a browser or other program, the program will understand how to open it.

1
  • Thank you. Worked flawlessly. Didn't realize I could just save the file as a variable Had an issue calling it but I solved it. Thank you very much dale! driver.get("file://"+reportFileName);
    – Christian
    Commented Jan 20, 2017 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.