Home RoadMap Blog Contact us Learn

How to Generate Cucumber Extent Reports in Selenium WebDriver

How to Generate Cucumber Extent Reports in Selenium WebDriver

Cucumber Extent Reports

In this post, you will learn how to generate Cucumber Extent Reports in a Selenium WebDriver project. Follow these steps to integrate Extent Reports into your automation testing project.

1. Add Dependencies

Ensure you have the necessary dependencies in your pom.xml file for both Cucumber and ExtentReports.

<!-- Cucumber dependencies -->
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>7.11.0</version>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-testng</artifactId>
    <version>7.11.0</version>
</dependency>

<!-- ExtentReports dependencies -->
<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>5.0.9</version>
</dependency>
<dependency>
    <groupId>tech.grasshopper</groupId>
    <artifactId>extentreports-cucumber6-adapter</artifactId>
    <version>3.1.0</version>
</dependency>

2. Cucumber Test Runner

Modify the TestRunner class to include the plugin for generating the Extent Report.

import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;

@CucumberOptions(
    features = "src/test/resources/features", 
    glue = "stepDefinitions",
    plugin = {
        "pretty",
        "html:target/cucumber-html-report",
        "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:" 
    }
)
public class TestRunner extends AbstractTestNGCucumberTests {
}

3. Extent Report Configuration

Create an extent-config.xml file in your src/test/resources directory for Extent report configuration. Here’s a basic example:

Extent Report Configuration (extent-config.xml)

        <?xml version="1.0" encoding="UTF-8"?>
        <extentreports>
            <!-- Report Configuration -->
            <configuration>
                <!-- Theme options: standard (default), dark -->
                <theme>standard</theme>

                <!-- Encoding type, default is UTF-8 -->
                <encoding>UTF-8</encoding>

                <!-- Document title displayed in the browser tab -->
                <documentTitle>Automation Test Report</documentTitle>

                <!-- Report name displayed in the report -->
                <reportName>Automation Test Execution Report</reportName>

                <!-- Time stamp format for logs, steps, etc. -->
                <timeStampFormat>yyyy-MM-dd HH:mm:ss</timeStampFormat>

                <!-- Additional Settings -->
                <protocol>HTTPS</protocol>
                <projectName>Selenium Cucumber Automation Project</projectName>

                <!-- Chart settings -->
                <charts>
                    <!-- Enable or disable charts, default is true -->
                    <enable>true</enable>

                    <!-- Pie chart settings -->
                    <pieChart>
                        <visible>true</visible>
                    </pieChart>
                </charts>
            </configuration>

            <!-- Custom CSS Styling -->
            <customStyles>
                <!-- Custom CSS code to style the report -->
                <css><![CDATA[
                    .test-name {
                        font-size: 18px;
                        color: #00bcd4;
                    }
                    .step-details {
                        font-family: 'Courier New', Courier, monospace;
                    }
                ]]></css>
            </customStyles>

            <!-- Custom JavaScript -->
            <customScripts>
                <!-- Custom JavaScript code to modify behavior -->
                <js><![CDATA[
                    document.addEventListener("DOMContentLoaded", function() {
                        console.log('Custom script loaded');
                    });
                ]]></js>
            </customScripts>
        </extentreports>
    

4. Add extent.properties

You also need to add an extent.properties file in the src/test/resources directory to specify the report's output location.

extent.reporter.spark.start=true
extent.reporter.spark.config=src/test/resources/extent-config.xml

5. Execution

After executing your test using Cucumber’s TestNG runner, the Extent Reports will be generated in the target folder. The default report will be in target/spark.html.

With these configurations, Cucumber tests will generate Extent Reports automatically after execution.

Recent Posts