Cucumber BDD Extent Report

This tool helps you to generate the custom cucumber-jvm report using ExtentReports plugin.

The ExtentReports API is developed by Anshoo Arora. This is one of the best reporting API available for testing world. Here I present a cucumber java based plugin to help you generate the feature-rich extent report easily.


Usage

If you are using a maven based project, you can directly add this library as a dependency:

<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>2.0.1</version>
</dependency>

Please note that Java 8+ and adding the dependency of ExtentReport v3.0.2+ is mandatory.

If not, download the jar from here.


Getting Started

Runner Class example:

Create a runner class and add the com.cucumber.listener.ExtentCucumberFormatter as a plugin followed by the report file as input.

A sample example is show below:

package com.cucumber.runner;

import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.runner.RunWith;

import java.io.File;

/**
* A sample test to demonstrate
*/
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"src/test/resources/features"},
glue = {"com.cucumber.stepdefinitions"},
plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
)
public class RunCukesTest {

@AfterClass
public static void setup() {
Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
Reporter.setSystemInfo("user", System.getProperty("user.name"));
Reporter.setSystemInfo("os", "Mac OSX");
Reporter.setTestRunnerOutput("Sample test runner output message");
}

}

The above example shows a JUnit runner. However, you can use the TestNG runner too.
Also make sure the loadXMLConfig, setSystemInfo and setTestRunnerOutput methods should be in your @AfterClass method.


Logging

User can add logs at any step and those logs will be captured and attached to the corresponding step. The log should be added as follows:

Reporter.addStepLog("Step Log message goes here");

In case any log to be added at the scenario level, the following can be done:

Reporter.addScenarioLog("Scenario Log message goes here");

Adding screenshot / screen cast

The screenshot or screen cast can be added from any of the step as follows:

Reporter.addScreenCaptureFromPath("absolute screenshot path"); Reporter.addScreenCastFromPath("absolute screen cast path");

Demo

Scenario

Scenario report

Scenario Outline with Examples data table

Scenario outline report

Hope this helps everyone.

P.S: Hit like and share if you found this helped.


Originally published at www.vimalselvam.com on March 6, 2017.

Like what you read? Give Vimal Raj a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.