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
1 Answer 1
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
Explore related questions
See similar questions with these tags.