How to Add Extent Report in the Selenium-Cucumber Framework

In the Test automation framework, it is important to generate visually appealing HTML reports for effective communication of test execution results. In this post, we will learn how to integrate Extent Report in the Selenium Cucumber Framework.

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:

Before generating the Extent reports few requisites need to be followed.

  1. Java Development Kit (JDK) installed on your system.
  2. Maven installation for managing dependencies.
  3. Selenium WebDriver for browser automation.
  4. Add Cucumber Java dependence.
  5. Add TestNG Dependence.

Integration of Extent Report in Test Automation Framework

Follow step by step to integrate Extent Report successfully in the Selenium test automation framework.

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

Open IDE and open the Selenium-TestNg-BDD project. Add the below dependency in the pom.xml file.

 <dependency>
     <groupId>tech.grasshopper</groupId>
      <artifactId>extentreports-cucumber7-adapter</artifactId>
      <version>1.14.0</version>
  </dependency>

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

Navigate to the src/test/resources folder and add a new properties file. Name it ‘extent.properties’ and add the below code.

#Extent-Report
extent.reporter.spark.start=true
extent.reporter.spark.out=automation-report.html

#PDF Report
extent.reporter.pdf.start=true
extent.reporter.pdf.out=PdfReport/automation-report.pdf

#HTML Report
extent.reporter.html.start=true
extent.reporter.html.out=HtmlReport/automation-report.html

screenshot.dir=test-output/
screenshot.rel.path=../

basefolder.name=reports/
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

Go to the project and open the Cucumber Runner file. Add the avent stack extent report plugin inside the plugin section of the CucumberOptions annotation.

@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 execute your TestRunner class and then refresh the project. A base folder will be created named reports. Open this folder, under this folder we will see the HTML report, PDF report and spark report.

ExtentReport

Right-click on the HTML Report and open it in the browser. This report contains information related to the test execution summary like total test cases executed, total test cases passed, failed test cases, Start date, duration etc. Open and analyse pdf reports and spark reports.

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. In the XML config file, we can set the elements :

  1. Theme: Dark or Standard.
  2. Document encoding: UTF-8
  3. Document Title: Will display on the browser Tab.
  4. Report Name: Will display on the top of the report.
<?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. Read this XML file in your test script. Now, execute your test script and refresh the project. The report will be generated 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.

Leave a Reply

Discover more from AutomationQaHub

Subscribe now to keep reading and get access to the full archive.

Continue reading