0% found this document useful (0 votes)
6 views

Cucumber_Selenium_Reporting

The document provides an overview of reporting in Cucumber and Selenium automation, highlighting the importance of tracking test execution and results. It details various reporting tools such as Default Cucumber Reports, Extent Reports, Allure Reports, and TestNG Reports, along with integration steps for each. Additionally, it includes a complete demo for setting up a Maven project with necessary dependencies and configurations for effective reporting.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Cucumber_Selenium_Reporting

The document provides an overview of reporting in Cucumber and Selenium automation, highlighting the importance of tracking test execution and results. It details various reporting tools such as Default Cucumber Reports, Extent Reports, Allure Reports, and TestNG Reports, along with integration steps for each. Additionally, it includes a complete demo for setting up a Maven project with necessary dependencies and configurations for effective reporting.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

Reporting in Cucumber and Selenium

========================================
|-Reporting is essential in Cucumber and Selenium automation to track test
execution, failures, and success rates.

|-Different reporting tools provide detailed insights, logs, and screenshots.

Types of Reporting in Cucumber & Selenium


=============================================

✅ 1. Default Cucumber Reports

|-Cucumber provides built-in reports with the pretty, json, and html formats.

How to Generate Default Reports?


=====================================
|-In your Test Runner (TestRunner.java), add these plugins:

@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions",
plugin = {
"pretty",
"html:target/cucumber-reports.html",
"json:target/cucumber.json"
}
)

✔ Pretty → Prints readable output in the console.


✔ HTML Report → Generates a cucumber-reports.html file.
✔ JSON Report → Generates cucumber.json, used for advanced reporting.

✅ 2. Extent Reports (Advanced HTML Reports)


================================================
|-Extent Reports provide graphical, detailed, and customizable reports.

Steps to Integrate Extent Reports in Cucumber


===================================================
Step 1: Add Dependency (pom.xml)

<dependency>
<groupId>tech.grasshopper</groupId>
<artifactId>extentreports-cucumber7-adapter</artifactId>
<version>1.7.0</version>
</dependency>

📌 Step 2: Update TestRunner.java

@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions",
plugin = {

"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"
}
)
📌 Step 3: Configure Extent Report (extent-config.xml) Create an extent-config.xml
file in src/test/resources/:

<extentreports>
<configuration>
<theme>dark</theme>
<encoding>UTF-8</encoding>
<reportName>Cucumber Extent Report</reportName>
<documentTitle>Test Automation Report</documentTitle>
</configuration>
</extentreports>

✅ After Execution → Open target/extent-report/index.html in a browser.

✅ 3. Allure Reports (Interactive Reports)


==============================================
|-Allure Reports provide rich visualization, test trends, and logs.

Steps to Integrate Allure Reports


=================================
📌 Step 1: Add Dependencies (pom.xml)

<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-cucumber7-jvm</artifactId>
<version>2.21.0</version>
</dependency>

📌 Step 2: Update TestRunner.java


@CucumberOptions(
features = "src/test/resources/features",
glue = "stepDefinitions",
plugin = {
"io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"
}
)
📌 Step 3: Generate Allure Report Run tests and generate the report:

mvn clean test


mvn allure:serve

This opens an interactive web report.

✅ 4. TestNG Reports (For Selenium with TestNG)


====================================================
TestNG generates an index.html report in the test-output/ folder.

Enable TestNG Reports in testng.xml

<suite name="Test Suite">


<listeners>
<listener class-name="org.testng.reporters.XMLReporter" />
</listeners>
</suite>
After running tests, open:

test-output/index.html
Summary
Reporting Tool Feature File Location
Cucumber HTML Report Default, simple HTML target/cucumber-
reports.html
Extent Reports Advanced, detailed UI, graphs target/extent-
report/index.html
Allure Reports Interactive UI, test trends
allure-report/index.html
TestNG Reports Basic HTML for Selenium-TestNG test-
output/index.html

Complete Demo For Reporting


===============================

Step-1 Create a Maven Project

Cucumber_Reporting_Project/
|-src/main/java
|-src/main/resources
|-src/test/java
|-com.automation.stepDefinitions
|-LoginStep.java
|-com.automation.runner
|-TestNGRunner.java
|-src/test/resources
|-Features
|-Login.feature
|-extent-config.xml

Step-2 Add the required dependencies in pom.xml


=====================================================
<dependencies>

<!-- Extent Reports Dependencies -->


<dependency>
<groupId>com.aventstack</groupId>
<artifactId>extentreports</artifactId>
<version>5.0.9</version>
</dependency>

<!-- https://mvnrepository.com/artifact/tech.grasshopper/extentreports-cucumber7-
adapter -->
<dependency>
<groupId>tech.grasshopper</groupId>
<artifactId>extentreports-cucumber7-adapter</artifactId>
<version>1.13.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java -->


<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.20.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.10.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.20.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.28.1</version>
</dependency>
</dependencies>

Step 3: Feature File (login.feature)


Feature: Login Functionality

Scenario: Successful login with valid credentials


Given User is on the login page
When User enters username "testuser" and password "password123"
And User clicks on login button
Then User should see the homepage

Step 4: Step Definitions (LoginSteps.java)


package com.ecommerce.stepDefinitions;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class LoginStep {

@Given("User is on the login page")


public void user_is_on_the_login_page() {
}

@When("User enters username {string} and password {string}")


public void user_enters_username_and_password(String string, String string2)
{

@When("User clicks on login button")


public void user_clicks_on_login_button() {

@Then("User should see the homepage")


public void user_should_see_the_homepage() {
}
}

Step 5: Configure Extent Reports (extent-config.xml)


Create an extent-config.xml file inside src/test/resources:

<extentreports>
<configuration>
<theme>dark</theme>
<encoding>UTF-8</encoding>
<protocol>https</protocol>
<reportName>Cucumber Extent Report</reportName>
<documentTitle>Test Automation Report</documentTitle>
<reportHeadline>Cucumber Extent Report Example</reportHeadline>
</configuration>
</extentreports>

Step 6: Test Runner (TestNGRunner.java)


Configure the Cucumber Test Runner to integrate Extent Reports:

package com.ecommerce.runner;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;

import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.CucumberOptions;

@CucumberOptions(
features = "src/test/resources/Features/Login.feature", // Path to
feature files
glue = "com.ecommerce.stepDefinitions" , // Step definitions package
plugin = {
"pretty",
"html:target/Cucumber-Reports/cucumber_report.html",
"json:target/Cucumber-Reports/cucumber_report.json",
"junit:target/Cucumber-Reports/cucumber_report.xml",

"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:target/
Cucumber-Reports" // Extent Report Adapter

}
)
public class TestNGRunner extends AbstractTestNGCucumberTests{

You might also like