top of page
hand-businesswoman-touching-hand-artificial-intelligence-meaning-technology-connection-go-

Reports in Cucumber Framework

It is very vital to generate a concise report as it can give overview about the stability of a product. Hence, while we are automating our test scenario with Cucumber, it is essential to know, how better we can generate our Cucumber test reports.


Pretty Format(HTML Report)

Pretty Format generates the Cucumber test report in the HTML format, i.e. an HTML file. It is the most readable report format. It generates the report in the same way as it is a feature file so it becomes easy to track the test results. Also, we can specify the location where we want this report to be placed after the test execution. We can specify target directory for report as any local directory of the machine where the test will run.

Enough for introduction !!!

Let’s understand how to generate HTML reports in Cucumber.

We will use Eclipse IDE, Java as programming language and Cucumber as BDD framework.


Step 1- Create a Maven project in Eclipse named as CucumberReports.

Step 2 – Add below dependencies in pom.xml to work in cucumber framework with Junit.


<dependencies>

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

<dependency>

<groupId>io.cucumber</groupId>

<artifactId>cucumber-java</artifactId>

<version> 7.2.3 </version>

</dependency>


<!-- https://mvnrepository.com/artifact/junit/junit -->

<dependency>

<groupId>junit</groupId>

<artifactId>junit</artifactId>

<version>4.13.2</version>

<scope>test</scope>

</dependency>

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

<dependency>

<groupId>io.cucumber</groupId>

<artifactId>cucumber-junit</artifactId>

<version> 7.2.3 <version>

<scope>test</scope>

</dependency>


Step 3- Create a package named Feature under src/test/resources

Step 4- Create CucumberReport.feature as feature file.


Feature: Check for Login functionality


Scenario: Welcome Page Login verification

Given User is on Welcome Page

When User clicks on Login button

Then Welcome page should be displayed


Step 5- Create a package for step definition under src/test/java as StepDefinition. Create a class called CucumberReport.java inside StepDefinition package.


package StepDefinition;


import io.cucumber.java.en.*;


public class CucumberReport {

@Given("User is on Welcome Page")

public void user_is_on_welcome_page() {

System.out.println("User on welcome page");

}


@When("User clicks on Login button")

public void user_clicks_on_login_button() {

System.out.println("User clicks on Login button");

}


@Then("Welcome page should be displayed")

public void welcome_page_should_be_displayed() {

System.out.println("Welcome page should be displayed");

}

}


Step 6- Create a runner class as TestRunner.java. This runner file is to build the communication between feature file and StepDefinition file. It is also very useful when we want to run our feature files with some conditions using tags or we want to run specific feature file, all things are control by TestRunner class.


package StepDefinition;


import org.junit.runner.RunWith;


import io.cucumber.junit.Cucumber;

import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)

@CucumberOptions(features=".\\src\\test\\resources\\Feature\\CucumberReport.feature",

glue={"StepDefinition"},

plugin = {"pretty","json:target/cucumber-reports/reports.json",

"junit:target/cucumber-reports/Cucumber.xml",

"html:target/cucumber-reports/reports2.html"},monochrome = true,

dryRun = false)

public class TestRunner {


}


Step 7- Click right click on TestRunner.java file to choose Run As -> Junit Test. After successful build three types of reports will be generated HTML report, XML report, Json report. Among all three types of reports, HTML reports are the most readable. In plugin parameter, we have to mention the target folder and the destination folder for the reports to be generated.

plugin = {"pretty","json:target/cucumber-reports/reports.json",

"junit:target/cucumber-reports/Cucumber.xml",

"html:target/cucumber-reports/reports2.html"}

























When we open reports2.html by double clicking, it opens in browser and gives us the clear picture about the feature file implemented.



It is very easy to generate inbuilt HTML reports for Cucumber as we don't need to add any dependency in pom.xml but we can explore many other features for a report. In the next blog, I will discuss about Extent reports which gives better overview about our test cases and scenarios.

Thanks for visiting and keep reading!!!!



4,270 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page