Generating Cucumber Reports for Selenium Java Tests
When it comes to Behavior-Driven Development (BDD), Cucumber paired with Selenium and Java is a popular combination. Cucumber allows you to write test scenarios in plain English using Gherkin syntax, which makes test cases easy to understand and maintain. However, to evaluate the results of these tests efficiently, it's essential to generate readable and insightful reports. Cucumber provides several reporting options that integrate seamlessly with Selenium Java tests.
In this blog, we'll guide you through how to generate Cucumber reports for Selenium tests written in Java, using plugins and tools such as the built-in Cucumber HTML reports and third-party reporting frameworks like Extent Reports and Cucumber Reporting Plugin.
Why Reports Matter
Test reports are crucial in any test automation framework because they:
Offer a summary of passed, failed, and skipped scenarios
Provide error logs and stack traces for debugging
Help stakeholders and QA teams understand test coverage and quality
Serve as documentation for test execution history
Project Setup
Before diving into report generation, ensure you have a Maven-based Selenium-Cucumber Java project set up.
Key dependencies in pom.xml:
xml
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.14.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.19.1</version>
</dependency>
Step 1: Cucumber HTML Reports
Cucumber natively supports HTML report generation with a simple plugin configuration in your runner class.
Example Test Runner:
java
import org.junit.platform.suite.api.ConfigurationParameter;
import org.junit.platform.suite.api.IncludeEngines;
import org.junit.platform.suite.api.SelectClasspathResource;
import org.junit.platform.suite.api.Suite;
import static io.cucumber.junit.platform.engine.Constants.*;
@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, html:target/cucumber-reports.html")
public class TestRunner {
}
This will generate a readable HTML report at:
target/cucumber-reports.html
Step 2: Cucumber Reporting Plugin (Advanced)
For more detailed, visually rich reports, use the Cucumber Reporting Plugin by masterthought.
Add plugin to pom.xml:
xml
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.7.5</version>
<executions>
<execution>
<id>generate-cucumber-html-reports</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>Selenium Cucumber Report</projectName>
<reportOutputDirectory>${project.build.directory}/cucumber-report</reportOutputDirectory>
<cucumberOutput>${project.build.directory}/cucumber.json</cucumberOutput>
</configuration>
</execution>
</executions>
</plugin>
Modify the runner to include JSON output:
java
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, json:target/cucumber.json")
Then run:
bash
mvn clean verify
Find the report in:
target/cucumber-report/index.html
Step 3: Extent Reports with Cucumber
To use Extent Reports, add dependencies:
xml
<dependency>
<groupId>tech.grasshopper</groupId>
<artifactId>extentreports-cucumber7-adapter</artifactId>
<version>1.7.0</version>
</dependency>
Then, update your runner to include:
java
@ConfigurationParameter(key = PLUGIN_PROPERTY_NAME, value = "pretty, io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm")
And add extent.properties file in your src/test/resources:
ini
extent.reporter.spark.start=true
extent.reporter.spark.out=target/extent-report/spark.html
Final Thoughts
Cucumber reports play a vital role in the success of automated Selenium test frameworks by providing detailed feedback to developers and QA teams. Whether you're using the built-in HTML reports or integrating powerful tools like Extent Reports or Masterthought Reporting, you'll gain deeper insights into test results, coverage, and overall project health.
Learn Selenium with Java Training
Read More: Implementing Hooks in Selenium Java Cucumber Tests
Read More: Data Tables in Cucumber for Selenium Java AutomationRead More: Mapping Step Definitions in Selenium Java Cucumber Framework
Visit Our IHUB Talent Institute Hyderabad
Get Direction
Comments
Post a Comment