Saturday, April 10, 2021

Generate most preferred Cucumber JVM report

Today, We will see how to generate cucumber report using maven cucumber reporting plugins, So basically cucumber is very popular tool to do Behavioral-driven development. In cucumber there are number of plugins available for different reporting like Extent report, PDF report, and Cucumber json report etc.

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 report

a. 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"}
view raw testRunner.java hosted with ❤ by GitHub

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 {
}
}
view raw gistfile1.java hosted with ❤ by GitHub
POM.xml to be updated as below.
<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>
view raw pom.xml hosted with ❤ by GitHub

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 repor https://github.com/damianszczepanik/cucumber-reporting

 

Here is the detailed instruction on publishing the cucumber report on the Jenkins build server: https://github.com/jenkinsci/cucumber-reports-plugin/wiki/Detailed-Configuration

No comments:

Post a Comment

How to install Java on EC2

***************************************** How to install Java on EC2 ***************************************** To be continued, In this post...

All Time Popular Post