1

I have a Cucumber based Selenium framework written in Java. Now, for reporting i use some common plugins/libraries like Extent report. That is fine.

However, i want to create my own custom HTML report, where each test step inside a Cucumber scenario is logged with say Apache Log4j and corresponding screenshot is linked to the step.

Is there any dependency/lib that can be used to create own .html format reports after the test run completes?

Something like this....

Scenario 1
Test step 1 -------------- Screenshot link
Test step 2 ---------------screenshot link
Scenario 2
Test step 1 -------------- Screenshot link
Test step 2 ---------------screenshot link
asked Nov 30, 2021 at 6:30

1 Answer 1

0

You can create a custom HTML file using the FileWriter class of Java.

I used the same to create a custom HTML test report for one of my projects.

In that projects, everything that I wanted in the report, I added it to an array with each step execution.

At the end of the test, I wrote all the data gathered within the array into the HTML file using FileWriter.

Here is a sample code:

File resultFile;
Writer fileWriter;
resultFile = new File(Results.html");
// if file doesn't exists, then create it...
if (!resultFile.exists()) {
 resultFile.createNewFile();
}
fileWriter = new FileWriter(resultFile.getAbsoluteFile());
fileWriter.write("<html><title>Test result</title><body>");
fileWriter.write("Your text OR your Log4j entries OR <span>HTML with custom result</span> goes here...");
fileWriter.write("Can do more than one writes to single file.");
fileWriter.write("It appends data to file.");
fileWriter.write("</body></html>");
fileWriter.close();

and few reference links for the FileWriter class:

https://www.w3schools.com/java/java_files_create.asp

https://www.geeksforgeeks.org/filewriter-class-in-java/

https://www.javatpoint.com/java-filewriter-class

answered Nov 30, 2021 at 8:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.