To use Extent Reports in Cucumber for reporting test execution results in a visually appealing and structured format, follow these steps:
What is Extent Report?
Extent Reports is a reporting library that provides a rich HTML-based test execution report. You can integrate it with Cucumber to generate reports that include test status, steps, screenshots, and logs.
Steps to Integrate Extent Reports with Cucumber
1. Add Maven Dependencies
<dependencies> <!-- Cucumber dependencies --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>7.14.0</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-testng</artifactId> <version>7.14.0</version> </dependency> <!-- Extent Reports --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>5.1.1</version> </dependency> <!-- Extent Cucumber Adapter --> <dependency> <groupId>tech.grasshopper</groupId> <artifactId>extentreports-cucumber7-adapter</artifactId> <version>1.7.0</version> </dependency> </dependencies>
2. Create
extent.properties file (in src/test/resources)extent.reporter.spark.start=true extent.reporter.spark.out=target/ExtentReports/SparkReport.html extent.reporter.avent.start=false extent.reporter.bdd.start=false extent.reporter.logger.start=false
This configures the Extent Spark Reporter to generate an HTML report in
target/ExtentReports/.3. Create Test Runner Class
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-html-report.html", "json:target/cucumber.json", "timeline:test-output-thread/", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:" }, monochrome = true ) public class TestRunner extends AbstractTestNGCucumberTests { }
4. Sample Step Definition
package stepdefinitions; import io.cucumber.java.en.Given; public class LoginSteps { @Given("User is on the login page") public void user_is_on_the_login_page() { System.out.println("User is on login page"); } @Given("User enters valid credentials") public void user_enters_valid_credentials() { System.out.println("User enters credentials"); } @Given("User is navigated to the home page") public void user_is_navigated_to_the_home_page() { System.out.println("User navigates to home page"); } }
5. Sample Feature File
Create a feature file at
src/test/resources/features/login.feature
Feature: Login Feature Scenario: Valid Login Given User is on the login page And User enters valid credentials Then User is navigated to the home page
Running the Tests:
Run your test runner class (TestRunner.java) as a TestNG Test. After execution:
A detailed report will be available at:
target/ExtentReports/SparkReport.html
Benefits of Extent Reports
Beautiful HTML reports.
Easy to customize.
Supports screenshots and logs.
Works well with parallel execution.
No comments:
Post a Comment