Creating Cucumber Extent Report the Right way.

Praveen David Mathew
4 min readMay 11, 2020

--

The right way is to use custom formatter (Plugins)

So what does this means ?

We are going to create our own report plugin using Extent report.

As in TestNG reporting, where we override the TestNG listeners to tell TestNG what to do for each action or events,

Here, we implements Cucumber listener class to listen to cucumber events and tell it what to do for each event.

Cucumber sends events for each action like scenario started, step started, step finished etc to this instance of the listener. So here we handle these events and tell cucumber what to do with these events (In our case we will tell it to log it to extent report).

There are two listener interfaces:

  1. EventListener
  2. ConcurrentEventListener

So as the name suggests, concurrentEventListener is thread-safe and the other is not. The implementation is exactly the same so we will use only the concurrentEventListner so that our framework is threadsafe when we have to run things in parallel.

Our TestListener :

package cucumberHooks;import com.aventstack.extentreports.ExtentReports;import com.aventstack.extentreports.ExtentTest;import com.aventstack.extentreports.Status;import com.aventstack.extentreports.gherkin.model.Feature;import com.aventstack.extentreports.gherkin.model.Given;import com.aventstack.extentreports.gherkin.model.Scenario;import com.aventstack.extentreports.reporter.ExtentSparkReporter;import com.aventstack.extentreports.reporter.configuration.Theme;import io.cucumber.plugin.EventListener;import io.cucumber.plugin.event.EventPublisher;import io.cucumber.plugin.event.PickleStepTestStep;import io.cucumber.plugin.event.TestCaseStarted;import io.cucumber.plugin.event.TestRunFinished;import io.cucumber.plugin.event.TestRunStarted;

--

--

Praveen David Mathew

An open source advocator/WebdriverIO Projectcommiter/Postman Supernova/Postman-html-extra contributor/Stack overflow sqa moderator/Speaker