Although Cucumber has several built in reporting options which are perfectly serviceable for technical users, they are not the beautiful and simple reports that are easy to understand for less technical users or clients.

Extent reports is a lovely, fairly simple to set up reporting plugin. It shows the simple colour coded view that is easy to take in at a glance and makes it easy to understand the data presented.

Here we describe how to add and produce extent reports for IntelliJ with Cucumber and Java, and what to update in the Jenkinsfile to get the Extent reports generated as part of Continuous Integration.


Add dependencies

Add the dependencies for cucumber extent reports and and the extent report libraries. These versions have been tested and they work together. Check maven repositories for the latest versions, however be aware later versions may not play nicely together.

        <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>4.0.8</version>
        </dependency>

Create extent-config.xml

In the folder structure, Right click on the "src" folder and select new > file
Name it extent-config.xml
Enter the following information:

<?xml version="1.0" encoding="UTF-8"?>
<extentreports>
    <configuration>
        <!-- report theme --> <!-- standard, dark -->
        <theme>standard</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>ToolsList - Cucumber Framework</documentTitle>

        <!-- report name - displayed at top-nav -->
        <reportName>ToolsList - Cucumber Report</reportName>

        <!-- global date format override -->  <!-- defaults to yyyy-MM-dd -->
        <dateFormat>yyyy-MM-dd</dateFormat>

        <!-- global time format override -->   <!-- defaults to HH:mm:ss -->
        <timeFormat>HH:mm:ss</timeFormat>

        <!-- custom javascript -->
        <scripts>
            <![CDATA[
        $(document).ready(function() {

        });
      ]]>
        </scripts>

        <!-- custom styles -->
        <styles>
            <![CDATA[

      ]]>
        </styles>
    </configuration>
</extentreports>

Update the plugin

In your Cucumber Runner (RunCukes), change the plugin in the CucumberOptions to show:

 plugin = {"com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},

Code to generate the report

In your RunCukes, we will use the Testng annotation @AfterClass to create a method that will generate the report after the tests have completed.

In the class, enter the following:

@AfterClass
    public static void writeExtentReport() {
        Reporter.loadXMLConfig("src/extent-config.xml");
    }

Run tests and view report

Run your tests, using either the test runner in IntelliJ or Maven from the command line. The report will be generated in your target folder, under cucumber-reports

Right click on the file (report.html) in the folder and opt to open in browser.


Generating Extent Reports with Jenkins CI

In order to generate the Extent report from your Jenkins continuous integration pipeline, you need to update the reportDir and reportFiles in the publishHTML stage. These need to match the paths we defined in our test runner (RunCukes).

            post {
                always {
                    publishHTML([
                            allowMissing         : false,
                            alwaysLinkToLastBuild: false,
                            keepAll              : false,
                            reportDir            : 'target/cucumber-reports',
                            reportFiles          : 'report.html',
                            reportName           : 'BDD report',
                            reportTitles         : ''
                    ])
                }
            }