To generate cucumber report from maven cucumber reporting plugins we need to make the necessary changes in POM.xml file. You can find out the cucumber plugins here https://cucumber.io/docs/cucumber/reporting/
To generate the cucumber report we need to generate JSON report from which cucumber reporting plugins read .json file and will generate the report.
So, basically we need to generate two reporta. JSON report
b. Cucumber JVM report
In order to generate cucumber JSON report we need to add below plugins in TestRunnner.java also we need to update the plugins in POM.xml file as shown below.class
plugin = { "pretty", | |
"json:target/cucumber-reports/cucumber.json", | |
"html:target/cucumber-html-report"} | |
Below is the code snipped of complete TestRunnerClass.java class
@RunWith(Cucumber.class) | |
@CucumberOptions( | |
features = { "src/test/resources/parallel" }, | |
glue = {"parallel" },monochrome = true, publish = true, | |
plugin = { "pretty", | |
"json:target/cucumber-reports/cucumber.json", | |
"html:target/cucumber-html-report", | |
)} | |
public class MyTestRunner { | |
} | |
} |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-surefire-plugin</artifactId> | |
<version>${maven.surefire.version}</version> | |
<!-- adding below two line for parallel testing by testNG --> | |
<configuration> | |
<parallel>methods</parallel> | |
<useUnlimitedThreads>true</useUnlimitedThreads> | |
<testFailureIgnore>true</testFailureIgnore> | |
</configuration> | |
</plugin> | |
<!-- generate cucumber html report --> | |
<plugin> | |
<groupId>net.masterthought</groupId> | |
<artifactId>maven-cucumber-reporting</artifactId> | |
<version>2.8.0</version> | |
<executions> | |
<execution> | |
<id>execution</id> | |
<phase>verify</phase> | |
<goals> | |
<goal>generate</goal> | |
</goals> | |
<configuration> | |
<projectName>CucumberPOM</projectName> | |
<outputDirectory>target/cucumber-reports/advanced-reports</outputDirectory> | |
<cucumberOutput>target/cucumber-reports/cucumber.json</cucumberOutput> | |
<buildNumber>1</buildNumber> | |
<parallelTesting>false</parallelTesting> | |
<skip>false</skip> | |
<inputDirectory>${project.build.directory}/cucumber-reports</inputDirectory> | |
<jsonFiles> | |
<!-- supports wildcard or name pattern --> | |
<param>**/*.json</param> | |
</jsonFiles><!-- optional, defaults to outputDirectory if not specified --> | |
<classificationDirectory>${project.build.directory}/cucumber-reports</classificationDirectory> | |
<checkBuildResult>false</checkBuildResult> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> |
Now in order to run the project right click on project, select Run as Maven build and then click on maven build
Specify the maven goal as “clean install” as shown below Once the execution is done, refresh the project and check if report generated you would see to two report generated shown as below. Now right click on “feature-overview.html” and open with web browser.
You will see beautiful cucumber jvm report with all details.
Actually, There is a cucumber JVM report plugin which can be used to generate pretty HTML reports with charts showing the results of cucumber runs. This is mainly used to publish cucumber reports on the Jenkins build server. There is a maven plugin also to generate the same report in the local directory. We will see both here.
Here is the git hub project for the pretty cucumber HTML report
No comments:
Post a Comment