Java, NoSQL, SQL, REST API and other scary words, QA (eng)

Cucumber + ExtentReport

Prerequisites: Cucumber Again. From Requirements to Java Test

To create any simple Cucumber+Java test, we will need to create a glue file, that is pretty simple to do, because, if you don’t need all vhistles and blows on your first step – this will be enough:

package com.cucumber.StepDefinitions;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

        glue = "com.cucumber.StepDefinitions"
public class CukesRunner {

My favorite report engine is ExtentReports, so, let’s add a proper class:

package com.framework.common;

import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import org.testng.annotations.AfterSuite;

public class ExtentReport {
    public static ExtentReports extentReports;
    protected static ExtentTest extentTest;

    public static ExtentReports getExtentReport() {
        if (extentReports == null){
            extentReports = new ExtentReports(System.getProperty("user.dir") +"/ExtentReport/index.html", true);
        return extentReports;

    public static ExtentTest getExtentTest(String testName) {
        if (extentReports == null) {
        if (extentTest == null){
            extentTest = extentReports.startTest(testName);
            extentTest.log(LogStatus.INFO, testName + " configureation started");
        return extentTest;

    public void endSuite(){

and implementation is extremely simple:

ExtentReport.getExtentTest(getClass().getSimpleName()).log(LogStatus.INFO, "Run test for " + className);

This is how it looks like:

After that I tried to research if there are any ready to go plugins or examples about how to make reports in Gherkin-like format. I easily found one, but that was working with no problems only with Eclipse. Here is an example – (

There is a key problem – there will be no particular action description like I clicked here or there, but you will find an error description, if exists.

So, with Intellij Idea, all we need to do is to implement current solution :

It’s enough set dependency, but in case of Idea – you will need and file in your project (you don’t need copy with Eclipse for some reason). In fact, you will operate with the code like this during your Gherkin code execution:

com.aventstack.extentreports.ExtentTest feature = ExtentReport.getExtentTest();

com.aventstack.extentreports.ExtentTest scenario = feature.createNode(new GherkinKeyword("Scenario"), "Child1");
com.aventstack.extentreports.ExtentTest given = scenario.createNode(new GherkinKeyword("Given"), "Given2").info("info");
com.aventstack.extentreports.ExtentTest and = scenario.createNode(new GherkinKeyword("And"), "And3").info("info");
com.aventstack.extentreports.ExtentTest when = scenario.createNode(new GherkinKeyword("When"), "When4").info("info");
com.aventstack.extentreports.ExtentTest then = scenario.createNode(new GherkinKeyword("Then"), "Then5").pass("pass");

But it will be at least one problem – you will have a duplicates data like here to set proper name. I raised this question here:

Honestly, I could not highlight best reporting way for today with ExtentReports, hopefully, they will resolve existing problems. Please note that there are many not so fancy reporting engines for your Java + Cucumber tests (example:








3 thoughts on “Cucumber + ExtentReport

  1. Hi Admin,
    This is to inform you that the Image which you have used on your page, is ours [].
    So kindly take it down, as it is violation of content plagiarism.
    Sandeep Tiwari

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.