Cucumber provides built-in reporting plugins that generate reports in HTML, JSON, XML, and plain text formats. These reports help visualize test execution results.
In this section, you’ll learn how to:
1. Generate a basic HTML report using Cucumber’s built-in plugin
2. Embed screenshots for failed scenarios in the report
Add plugin in @CucumberOptions
The plugin option in the @CucumberOptions annotation is used to generate reports.
To generate an HTML report, include the following:
1. "pretty": Prints the Gherkin steps clearly in the console
2. "html:target/Reports/cucumber.html": Generates an HTML report in the target/Reports folder
Sample JUnit Runner Class
After running your tests, open the generated HTML report from: target/Reports/cucumber.html
Supported Formats
Format |
Plugin Syntax |
HTML |
"html:target/Reports/report.html" |
JSON |
"json:target/Reports/report.json" |
JUnit XML |
"junit:target/Reports/report.xml" |
Plain Text |
"summary" or "message" |
We can also use multiple format at once
Embedding Screenshots in HTML Report
If a scenario fails, you can attach a screenshot to the HTML report using this code in your Hooks.java file.