top of page

Reports, Parallel Execution, And Rerun of failed testcases with CUCUCMBER BDD framework.

Let us first try to understand that what is BDD Cucumber. Cucumber is a testing framework that supports Behavior Driven Development (BDD). It is written in plain English text called Gherkin. It is defined as a scenario of inputs, actions and outcomes. Gherkin interprets human input into the software concept of input/process and actions.

Main Elements in Cucumber are

· Feature File- Basically the user stories are written in the feature file in a predefined format using GIVEN, WHEN, THEN keywords. Other keyword which are used to support this framework are FEATURE, SCENARIO/SCENARIO OUTLINE, BACKGROUND. It is written in plain English.

· Step Definition: This is the part where the actual Automation test script is written.

· Runner class:- This class will use the Junit annotation @RunWith(), which tells JUnit what is the test runner class. It more like a starting point for Junit to start executing your tests.

Runner class is used to run the feature file & generate reports.

So now, we are going to discuss more elaborately about reports, Parallel Execution & rerun of the failed TestCases through the runner class in cucumber.


The output of the any test execution, has to be in format, which immediately depicts the overall results of the execution. Hence, our framework also should have the same capability to create output or generate test execution reports.

What are the various kinds of reports we can generate using Cucumber.

1. JSON / XML/ HTML reports:

When we execute Cucumber Scenarios, it automatically generates an output in the eclipse console. There is a default behavior associated with that output and we can also configure that output as per our needs also. For that we need to have pretty Plugin.

To make the reports to be in more readable format monochrome is set to true.

package Test_Runner;

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

@CucumberOptions(features = 		    {"src/test/resources/test.feature"}, 
			glue = { "step_definition" }, 
			plugin = { “pretty”,"html:target/test-reports/test_htmlreports.html", 
			monochrome = true)

			public class Test_Runner {

These reports are stored in the Target folder in the Eclipse

2. Cucumber output Reports :

Cucumber itself has provided a nice feature to generate reports. These are very basic reports.

We can create this report by creating a file under src/test/resources folder. The property File should contain the following

      cucumber.publish.enabled = true

The report link comes in the eclipse console after the execution.

3. Extend Report/Spark Reports

This is the advanced and one of the best reporting. It generates a PDF report & spark html report.

  • For this we need to add dependency in the pom.xml file. If you are using Java 8+ then add the following dependency


  • Next Add file under src/test/resources with the following content.




  • Then Add Extent Config to the Project under src/test/resources as extent-config.xml with the following content inside

<?xml version="1.0" encoding="UTF-8"?>
    <!-- report theme --> <!-- standard, dark -->
    <!-- document encoding -->  <!-- defaults to UTF-8 -->
    <!-- protocol for script and stylesheets -->   <!-- defaults to https -->
    <!-- title of the document -->
    <documentTitle>TestAutomation - Cucumber Framework</documentTitle>
    <!-- report name - displayed at top-nav -->
    <report Name> TestAutomation - Cucumber Report</reportName>
    <!-- global date format override -->  <!-- defaults to yyyy-MM-dd -->
    <!-- global time format override -->   <!-- defaults to HH:mm:ss -->
    <!-- custom javascript -->
       $(document).ready(function() {
    <!-- custom styles -->

  • Now the Last step for this reports is to add the plugin in the Runner Class with the following lines of code.

@CucumberOptions(features = {"src/test/resources/test.feature"},  
glue = { "step_definition" }, 
monochrome = true)

public class test_Runner {


The output report Looks like the following

4. Allure Reports

Allure Framework is a flexible lightweight multi-language test report tool.

  • For Allure Reporting we need to add the following dependencies in the POM.xml

<!-- -->
             <!-- -->

  • And also the following plugin in the POM.xml

           <argLine>-           javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/1.9.7/aspectjweaver-1.9.7.jar"

  • Then in the runner file add the following

@CucumberOptions(features = {"src/test/resources/test.feature"},  
glue = { "step_definition" }, 
plugin = { "pretty","io.qameta.allure.cucumber6jvm.AllureCucumber6Jvm"
monochrome = true)

public class test_Runner {


Now to view the allure report need to do the following steps:

  • Download the latest version as zip archive from either Maven Central or GitHub releases.

  • Unpack the archive to allure-commandline directory.

  • Navigate to bin directory.

  • Use allure.bat for Windows and allure for other Unix platforms.

  • Add allure to system PATH.

  • The easiest way is to, install nodejs: Download

now install allure-commandline tool using below command:

npm install -g allure-commandline

now just run the below command:

allure generate --clean && allure open

Or u can also execute from command line by going in the directory where allure-results directory is present. Then in the command line write allure serve

The Final Allure Reports Looks like


One of the most important advantage of test Automation is to reduce the execution time. This can be achieved by executing the test Suites in parallel. Cucumber can be executed in parallel using JUnit and Maven test execution plugins.

In JUnit, the feature files are run in parallel rather than scenarios, which means all the scenarios in a feature file will be executed by the same thread. You can use either Maven Surefire or Failsafe plugin to execute the runner

The steps involved to do parallel execution is as below:

  • Add Maven Failsafe plugin in the build section of POM.XML for the parallel execution


Here Few Point do keep in mind

1. Always provide the relative path of the runner file under <include > Tab

2. Depending upon the no of parallel execution required, set the number in <threadCount> tab to required specific number instead of useUnlimitedThreads

3. In case of multiple runners one can also set the parallel option to classesAndMethods or classes in addition to methods.


  • Add Timeline Formatter

For a visual representation of threads, add the timeline report using the plugin option of CucumberOptions annotation on a JUnit or TestNG runner.

@CucumberOptions(plugin= {"timeline:<report folder>"})

Below is a sample report of timeline Formatter.

  • Last step to execute in parallel. That can be achieved through the commandline. You need to be in the project directory where the runner file is. Then just use mvn verify to execute the features in parallel

Once mvn verify is done , we can see the threads in the command line too.


Let us first try to understand why rerun of the failed test cases are required & how important it is. Sometime we experience issues with inconsistent test results due to unstable environment. Some test would fail for no obvious reason and pass when you rerun. So if the rerun of failed testcases is automated then we have to put less effort in analyzing the failed testcases report which fails due to unstable environment. By using the rerun plugin we can achieve this in a very simple step but it reduces our effort to a huge extent.

  • Modify existing runner class.

Add rerun:target/rerun.txt to your plugin, so your runner class will look something like that. So the test_runner will look something like below:

@CucumberOptions(feature={“classpath:feature”}, glue{“path to stepdefs”}, plugin = {“rerun:target/rerun.txt” })

This will run all your tests and then list all failed scenarios in rerun.txt file under the target folder. The rerun.txt contains path to the feature file and line number for scenario that was failed.

  • Create another runner class.

  • Next step is to create a new runner class to run failed scenarios. The New runner will contain the below codes

@CucumberOptions(features = “@target/rerun.txt”, plugin = {“rerun:target/rerun.txt”})
public class FailedRunner {}

  • Add maven surefire plugin to your pom.xml

  • Running Tests

In order to use rerun option you need to execute maven goals from terminal, open the terminal and go to the folder where your pom.xml is located and then run “mvn clean test”

2,365 views0 comments
bottom of page