What are Cucumber Reports?
Cucumber Reports are test execution reports generated after running Cucumber tests (BDD tests written using Gherkin). These reports provide detailed insights into the execution of scenarios, steps, and features — including their status (passed/failed/skipped), duration, and even screenshots (if configured).
Why are Cucumber Reports Useful?
| Feature | Description |
|---|---|
| Readable Format | Provides human-readable output for business users and stakeholders. |
| Debugging | Helps in identifying which steps/scenarios failed and why. |
| Traceability | You can trace the execution from the feature file to the actual code. |
| Data-Driven Insights | Useful for analytics and continuous integration systems. |
Types of Reports in Cucumber
Cucumber natively supports multiple report formats:
| Report Format | Description |
|---|---|
| pretty | Human-readable output in the console |
| html | Static HTML report |
| json | Structured data for third-party tools |
| junit | XML format compatible with CI tools like Jenkins |
| rerun | Captures only failed scenarios for re-execution |
How to Generate Reports in Cucumber (Java)
We'll use Maven + Cucumber + TestNG as the base.
Step 1: Add Dependencies in pom.xml
<dependencies> <!-- Cucumber dependencies --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>7.15.0</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>7.15.0</version> </dependency> <!-- TestNG --> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>7.8.0</version> <scope>test</scope> </dependency> </dependencies>
Step 2: Create Feature File (
Login.feature)Feature: Login Feature Scenario: Successful login Given User is on login page When User enters valid username and password Then User should be redirected to the homepage
Step 3: Step Definition (
LoginSteps.java)package stepdefinitions; import io.cucumber.java.en.*; public class LoginSteps { @Given("User is on login page") public void user_on_login_page() { System.out.println("User on login page"); } @When("User enters valid username and password") public void user_enters_credentials() { System.out.println("Entered valid credentials"); } @Then("User should be redirected to the homepage") public void user_on_homepage() { System.out.println("Redirected to homepage"); } }
Step 4: Test Runner (
TestRunner.java)package runner; import io.cucumber.testng.AbstractTestNGCucumberTests; import io.cucumber.testng.CucumberOptions; @CucumberOptions( features = "src/test/resources/features", glue = {"stepdefinitions"}, plugin = { "pretty", "html:target/cucumber-reports/report.html", "json:target/cucumber-reports/report.json", "junit:target/cucumber-reports/report.xml" }, monochrome = true ) public class TestRunner extends AbstractTestNGCucumberTests { }
Step 5: Run Tests
Run the
TestRunner.javaas a TestNG Test.Reports will be generated in the
target/cucumber-reports/directory.
Sample Output Report Paths
| Format | Path |
|---|---|
| HTML | target/cucumber-reports/report.html |
| JSON | target/cucumber-reports/report.json |
| JUnit | target/cucumber-reports/report.xml |
Important points:
- Cucumber supports multiple report formats like
pretty,html,json, andjunit.
- Reports are configured using the
pluginoption in@CucumberOptions.
- Reports help in debugging, analyzing, and integrating with CI tools.
No comments:
Post a Comment