Skip to content

How to Add Extent Report in Selenium-Cucumber Framework

Extent Report

What is ExtentReport?

Extent Report is a powerful, open-source library used in testing automation frameworks for generating beautiful and user-friendly HTML reports. It allows the user to customize the report template by using custom CSS, JSON, or XML.
You can read more about it at https://www.extentreports.com/.

Prerequisite:

Create Maven Project
Add Cucumber Java dependence.
Add TestNG Dependence.

Steps to follow:

a) Add extent reports-cucumber6-adapter dependency in the pom.xml file.

 <dependency>
     <groupId>tech.grasshopper</groupId>
      <artifactId>extentreports-cucumber6-adapter</artifactId>
      <version>1.2.0</version>
      <scope>test</scope>
 </dependency>

b) Create a file named “extent. properties” in the src/test/resources folder.

Add the following lines to the file.

extent.reporter.spark.start=true
extent.reporter.spark.out=automation-report.html
screenshot.dir=test-output/
screenshot.rel.path=../
basefolder.name=reports/SparkReport
basefolder.datetimepattern=d-MMM-YY HH-mm-ss
extent.reporter.spark.vieworder=dashboard,test,exception,author,device,log
systeminfo.user={User name}
systeminfo.build={Build version}
systeminfo.AppName={App name}

c) Add the Plugin in TestRunner.java class

@CucumberOptions(
		features = { "src/test/resources/features" }, 
		glue = { "path of your step definition" }, 
		plugin = { "pretty",
		"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:" } 
		)

After completing all the setup and configuration run your TestRunner class and then refresh the project. A base folder will be created named reports, inside which a beautiful HTML report will be generated as:

ExtentReport

We can configure the extent report using an XML file or JSON file as well.

Extent Report configuration using XML:

To configure the extent report using XML we need to create an extent-config.xml file in the src/test/resources folder. Add the below configuration in the XML file.

<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
	<configuration>
		<!-- report theme -->

		<!-- standard, dark -->

		<theme>dark</theme>
		<!-- document encoding -->

		<!-- defaults to UTF-8 -->

		<encoding>UTF-8</encoding>
		<!-- protocol for script and stylesheets -->

		<!-- defaults to https -->

		<protocol>http</protocol>
		<!-- title of the document -->
		<documentTitle>Extent</documentTitle>
		<!-- report name - displayed at top-nav -->

		<reportName>App Web Report</reportName>
		<!-- location of charts in the test view -->

		<!-- top, bottom -->

		<testViewChartLocation>bottom</testViewChartLocation>
		<!-- custom javascript -->

		<scripts>

<![CDATA[
$(document).ready(function() {
});
]]>
		</scripts>
		<!-- custom styles -->
		<styles>
<![CDATA[
]]>
		</styles>
	</configuration>
</extentreports>

Other steps will remain the same. Execute your script and refresh the project. The report will generate inside the target/Html folder.

Customize Report Folder: When we execute the test script then the previous report will be overridden and a new report will generate. To overcome this we need to maintain the backup of all the test execution results. To do this we can add two properties to the properties file.

basefolder.name=Reports/SparkReport
basefolder.datetimepattern=d-MMM-YY HH-mm-ss

If there is a requirement to attach the screenshot to the extent report that can also be achieved by adding a few more properties to the .properties file.

screenshot.dir=Screenshots/
screenshot.rel.path=../Screenshots/

There are a few more properties that can be used to customize the extent reports as per the requirement. By Doing so users can get a more extensive and insightful perspective on the test results.