You are currently viewing Creating Allure Report With Cucumber – Easy Steps
Allure report

Creating Allure Report With Cucumber – Easy Steps

Spread the love

Allure report with cucumber java | Cucumber is a popular BDD (Behavior-Driven Development) framework that allows you to write tests in a human-readable format. While Cucumber offers powerful testing capabilities, customized test reports can lack visual appeal and detailed insights. Allure is a versatile reporting tool that interfaces seamlessly with Cucumber, allowing you to create visually stunning and informative test reports. In this guide, we will explore how to integrate Allure reports with Cucumber using Java.

Adding Allure reports to Cucumber in a Java project requires a few steps. Allure is a simple and powerful reporting tool that can enhance the visualization of your Cucumber test results. Here’s how you can integrate Allure with Cucumber in a Java project:

Prerequisites

Before we jump into the integration process, ensure you have the following in place:

  1. A Java project with Cucumber tests is already set up.
  2. Dependencies for both Cucumber and Allure added to your project (as mentioned in the guide).

Allure framework installation steps:

Start by adding required dependencies like allure-cucumber-jvm etc…

Maven:

<properties>
    <aspectj.version>1.8.10</aspectj.version>
</properties>

<dependencies>
    <dependency>
        <groupId>io.qameta.allure</groupId>
        <artifactId>allure-cucumber4-jvm</artifactId>
        <version>LATEST_VERSION</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.20</version>
            <configuration>
                <argLine>
                    -javaagent:"${settings.localRepository}/org/aspectj/aspectjweaver/${aspectj.version}/aspectjweaver-${aspectj.version}.jar"
                    -Dcucumber.options="--plugin io.qameta.allure.cucumber4jvm.AllureCucumber4Jvm"
                </argLine>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjweaver</artifactId>
                    <version>${aspectj.version}</version>
                </dependency>
            </dependencies>
        </plugin>
    </plugins>
</build>

Gradle

// Gradle
implementation 'io.qameta.allure:allure-cucumber5-jvm:2.17.3' // Latest version

Then execute mvn clean test goal. After tests executed allure JSON files will be
placed in allure-results directory by default.

Features

This adapter provides runtime integration allowing conversion of Gherkin dsl features into basic Allure features

Display Name

Titles for tests and suites are extracted at runtime from .feature files

Description

Feature’s description appears on every scenario

Steps

All scenario steps are automatically translated into allure steps

Adding Attachments

You can simply add an attachment in java code by annotating the method with @Attachment that returns either a String or byte[],

import io.qameta.allure.Attachment;

...

@Attachment
public String performedActions(ActionSequence actionSequence) {
    return actionSequence.toString();
}

@Attachment(value = "Page screenshot", type = "image/png")
public byte[] saveScreenshot(byte[] screenShot) {
    return screenShot;
}

Or you can also add Allure helper methods for this

import io.qameta.allure.Allure;

...

Allure.addAttachment("My attachment", "My attachment content");

Path content = Paths.get("path-to-my-attachment-contnet");
try (InputStream is = Files.newInputStream(content)) {
    Allure.addAttachment("My attachment", is);
}

Allure Framework official documentation

Sample code to Configure Cucumber to Generate Allure reports. This process involves specifying the Allure plugin and the location for generating JSON reports.

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {
        "io.qameta.allure.cucumber5jvm.AllureCucumber5Jvm",
        "json:target/cucumber-report/cucumber.json" // JSON report location
    },
    features = "src/test/resources/features",
    glue = "your.step.definitions.package"
)
public class CucumberTestRunner {
}

Generating and Viewing Allure Report with Cucumber Java:

To Generate the Allure Report you can use the following commands

Generate the Allure Report in JSON format

allure generate target/cucumber-report

To open the generated report in the default web browser

allure open
Allure report with cucumber

Method Overloading in Java

Conclusion

Combining Allure reports with Cucumber Java tests elevates your testing and reporting experience to new heights. By following the steps outlined in this guide, you can create beautiful and insightful test reports that improve performance, minimize errors, and provide valuable insights into your test suite’s performance Embrace and leverage the power of Allure your Cucumber test report moves to the next level.


Spread the love

Santosh Adhikari

Hello, it's me Santosh Adhikari, from Kathmandu, Nepal. I'm a student of Science and Technology. I love new challenges and want to explore more on Software Quality Assurance. I want to be a professional SQA. I'm also interested in Blogging, SEO activities.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments