2

In my selenium java, Cucumber framework, i use an excel spreadsheet test results report. Now, there is a requirement to make a HTML report after every run of the test. How can i code an HTML report. Is there any tool/plugin for that.

Which logs all test case activity in a HTML page(Using log4j) format and all screenshots links should be in the report.

1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Sep 18, 2022 at 18:45

3 Answers 3

3

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

You can add everything you want in the report into an array with each step execution.

At the end of the test, you can write 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();
1
  • 1
    This looks more helpful rather than using a full-fledged external library.
    – KaiVacakis
    Sep 19, 2022 at 4:59
0

Multiple ways to achieve this. I am sharing one of the simpler way I have used in my project :

package CucumberReport; 

import org.junit.runner.RunWith; 
import cucumber.junit.Cucumber; 

@RunWith(Cucumber.class) 
@Cucumber.Options( 
   format = {"pretty", "html:target/Destination"} ) 
  • Specifying pretty as a format option ensure that HTML report will be generated.
  • When we specify html:target/Destination - It will generate the HTML report
  • I have used this link while implementing. Hope this will help :)
0

Like most things, there are multiple solutions.

  1. Like the other answers have mentioned, you can create your own report solution.

  2. You can use an existing reporting library. Extent Reports and Allure reports are two of the most popular. They are HTML reports, they can log anything you send to it, and can include screenshots. They are well documented and can be straightforward to set up.

Your Answer

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

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