Built.io joins Software AG! Read all about the news.

Built.io Blog

Customized HTML Reporting in Selenium Web Driver



As automation testers, we need to generate customized reports to analyze test cases and categorize them with the proper status on a daily basis. Selenium, by default, does not provide any reporting mechanisms. To generate deep, insightful reports in Selenium, we can use the open source HTML reporting library called ExtentReport. This library is extremely helpful for testers, and is quite easy to use. It generates reports that show the summary of each step and each test case in a toggle view for quick analysis.


By using ExtentReport, you are able to access many reporting features that would otherwise not be available.

  • Categorizes test cases: We can assign a particular category to a test case depending on our requirements.
  • Simplifies analysis: Classifies the test based on the different statuses and gives a visual summary, which simplifies analyzing the report.
  • Allows insertion of logs: Permits insertion of logs in the HTML report, eliminating the need to generate the logfile separately.
  • Provides a filter option: We can filter the report based on categories and the current status of the test to avoid missing out on any category.
  • Additional information: Allows the addition of extra listings, such as system information and an author name in the report for its ease of use.
  • Interactivity: Screenshots and videos with their description can be easily inserted in the report to enhance the report and make it more user friendly.
  • Parallel execution: Supports parallel execution, that is, it generates a combined report depending on how your tests are structured as per the classes and methods. If you require a single report for run sessions, you can use only one instance of ExtentReports.


These are the requirements to use the ExtentReport library:

  • Java
  • Eclipse
  • Apache Maven
  • Selenium JAR
  • TestNG


For Java:

Download the JAR file of the ExtentReport library for the respective version of your Java from http://extentreports.com/, and add it to your project library.

For Maven:

Add the following Maven dependency to your POM.xml file and save it. Then update your Maven project. This will automatically download the JAR file from the Maven central repository.



Here are two demo test cases for generating the HTML report—one with status as pass and one with fail.

import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class ExtentReport {
ExtentReports report;
 ExtentTest test
  WebDriver driver;
      //pass scenario
@Test(priority = 1, enabled = true)
public void verifyHomePageTitle() {
report = new ExtentReports(
"D:\\ContenstackWorkspace\\Contentstack\\Result\\automationreport.html", true)
 test = report.startTest("Verify application Title")
 driver = new FirefoxDriver()
 test.log(LogStatus.INFO, "Browser started");
String title = driver.getTitle();
if (title.equals("Built.io – Build mobile apps fast, Connect your digital business, Deliver content everywhere")) {
test.log(LogStatus.PASS, "verify Title of the page");
} else {
test.log(LogStatus.FAIL, "verify Title of the page");
     //Fail  scenario
       @Test(priority = 2, enabled = true)
       public void verifyLogo() throws IOException {
              test = report.startTest("Verify logo of the application");
              String src = driver.findElement(By.xpath("//img[@class='img']"))
              if (src.equals("")) {
                     test.log(LogStatus.PASS, "verify logo");
              } else {
                     test.log(LogStatus.FAIL, "verify logo");
                     File scrFile = ((TakesScreenshot) driver)
                     FileUtils.copyFile(scrFile, new
                     String image= test.addScreenCapture("D:\\ContenstackWorkspace\\ContentStackUIAutomation\\screenshot\\img.jpg");
                     test.log(LogStatus.FAIL, "verify logo of  the application", image);

Here’s a screenshot elaborating the success and failure of the sample test cases:


Test and run

Perform the following steps to run the test case using the ExtentReport library:

  • Create a testNg.xml file.
  • Right-click on testNg.xml and navigate to Run As | TestNG suite.

    That's it, you're done! ExtentReport will automatically generate the HTML report of your test case.

    Like what you read? Join our community to get more technical information, chances to win prizes, and more: built.io/community

    Popular Posts

    Subscribe to our blog