web analytics

In this article, We will learn How to generate Extent Reports in Selenium WebDriver.

What are Extent Reports?

Extent Reports is an open-source reporting library useful for test robotization. It can be fluently integrated with major testing fabrics like JUnit, NUnit, TestNG, etc. These reports are HTML documents that depict results as pie maps. They also allow the generation of custom logs, shots, and other customized details.

Boost Customer Satisfaction, Find out Hidden Bugs In Your Software

Once an automated test script runs successfully, testers need to induce a test prosecution report. While TestNG does give a dereliction report, they don’t give the details.

Using Extent Reports in Selenium

Selenium range reports contain two important classes that are commonly used.

  • ExtentReports Class
  • ExtentTest Class


ExtentReports reports = new ExtentReports("Path of directory to store the resultant HTML file", true/false);
ExtentTest test = reports.startTest("TestName");

The ExtentReports class generates HTML reports based on the path specified by the verifier. Depending on the boolean flag, an existing report should be overwritten or a new report should be created. “True” is the default, which means that all existing data will be overwritten.

The ExtentTest class saves the test steps to a previously created HTML report.

Both classes can be used in the following integrated ways:

  • startTest: Prerequisites for running the test case.
  • endTest: Fulfill the following conditions of a test case.
  • Log: Record the status of each test step in the HTML report being generated.
  • Flush: Delete all previous data on a relevant report and create a brand new one.

The test state can be represented by the following values:

  • PASS
  • FAIL
  • SKIP
  • INFO
Syntax: extent reports in selenium

Report methods take into account two parameters. The first is the test status and the second is the message printed in the generated report.

How to generate Extent Reports in Selenium?

  1. Import the JAR file: degreereports-java-2.1.2.jar. After downloading the ZIP file, extract its contents to a folder.
  2. Add the JAR file to the build path of the project using the Build Path -> Set Build Path option.
  3. Create a new JAVA class for Scope Report with the following code.
package com.browserstack.demo;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class ExtentDemo {
static ExtentTest test;
static ExtentReports report;
public static void startTest()
report = new ExtentReports(System.getProperty("user.dir")+"ExtentReportResults.html");
test = report.startTest("ExtentDemo");
public void extentReportsDemo()
System.setProperty("webdriver.chrome.driver", "D:SubmittalExchange_TFSQAAutomation3rdpartychromechromedriver.exe");
WebDriver driver = new ChromeDriver();
test.log(LogStatus.PASS, "Navigated to the specified URL");
test.log(LogStatus.FAIL, "Test Failed");
public static void endTest()

Runs from the startTest method. It also initializes the Scope Reports object. Any valid custom path can be passed as a parameter to the Scope Reports object.

@Test: This class automatically does the following:

  • Open the Chrome browser with the URL https://www.google.com.
  • When you open the page, check that the page title is as expected.
  • Record the test case status as PASS/FAIL using the logging method described above.

@AfterClass: Post the condition to run the test case: end the test (using the endTest method) and clear the report.

How to generate Extent Reports in Selenium using NUnit?

Using setup fixture:
public abstract class Base
protected ExtentReports _extent;
protected ExtentTest _test;

protected void Setup()
var dir = TestContext.CurrentContext.TestDirectory + "\;

Related Post

QACraft-white logo

© Copyright 2024 QACraft Pvt. Ltd. All rights reserved.

Contact : +91 9157786796