[OLD] Cucumber-JVM 4 Report generation using ExtentReports Adapter plugin

UPDATE – The issue regarding the “java.lang.NoClassDefFoundError: cucumber/runtime/io/URLOutputStream” exception has been fixed, as per the artifact author, with the latest release An updated version of this article can be found here.

Introduction

This article deals with generating Extent reports for Cucumber-JVM version 4 using the extentreports-cucumber4-adapter plugin. The article details out the procedure to create Logger and HTML reports available in the Community Extent Report edition.

The various steps required for this are to add the plugin to the runner, add the adapter dependency to the POM, enable report generation and change report settings.

Source

The source code for the article is located here. The source code for extentreports-cucumber4-adapter plugin is located here.

Plugin addition

The extentreports-cucumber4-adapter plugin needs to be added to the CucumberOptions annotation of the runner.

@CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})

Add the colon ‘:’ at the end of the plugin argument, else below exception is thrown.

cucumber.runtime.CucumberException: You must supply an output argument to com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter.

POM Dependencies

The latest version of theĀ extentreports-cucumber4-adapter jar is 1.0.7 which will be primarily used here.

<dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-cucumber4-adapter</artifactId>
        <version>1.0.7</version>
        <scope>test</scope>
</dependency>

The extentreports-cucumber4-adapter version 1.0.7 POM includes version 4.0.1 of cucumber-core and cucumber-java jars which need to be excluded in case of lambda style stepdefinitions for cucumber-java8 from this dependency using the exclusion tag.

<dependency>
	<groupId>com.aventstack</groupId>
	<artifactId>extentreports-cucumber4-adapter</artifactId>
	<version>1.0.7</version>
	<exclusions>
		<exclusion>
			<groupId>io.cucumber</groupId>
			<artifactId>cucumber-java</artifactId>
		</exclusion>
	</exclusions>
        <scope>test</scope>
</dependency>

The extentreports-cucumber4-adapter jar needs to be modified for running with Cucumber version greater than 4.2.0.

Cucumber version 4.0.0 to 4.2.0

The extentreports-cucumber4-adapter version 1.0.7 jar from maven repository works by default for the following Cucumber versions 4.0.0, 4.0.1, 4.0.2, 4.1.0, 4.1.1, 4.2.0.

The POM for this configuration using version 4.2.0 is located here.

Cucumber version 4.2.1 to 4.4.0

The extentreports-cucumber4-adapter version 1.0.7 jar from maven repository does not work by default for Cucumber versions 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.2.5, 4.2.6, 4.3.0, 4.3.1, 4.4.0.

The reason is that the adapter requires the class URLOutputStream, which was moved to cucumber.runtime.formatter package and access changed to package protected in version 4.2.1. In the previous version it was a public class in cucumber.runtime.io package. Though this class exists in the github source of extentreports-cucumber4-adapter, it has not been included in the jar.

One way is to import the sources and use Maven to install the jar in the local repository. Other is to download an existing jar and use Maven Install plugin to add to local repository. Or use system scope in the Maven dependency.

There is an issue with running the 4.2.1 version in Windows due to incorrect cucumber path parsing.

Compile jar from source

The source code (master branch) for the adapter needs to be imported into the IDE. Change the version from 1.0.7 to 1.0.8. Use the maven command “clean install” to create an extentreports-cucumber4-adapter.jar version 1.0.8 in the local repository.

In the POM, the version of the adapter dependency needs to be changed to 1.0.8. This jar fetches the Cucumber version of 4.2.6, so as explained above this needs to excluded.

The POM for this configuration using version 4.4.0 is located here.

Maven Install 1.0.8 jar

The extentreports-cucumber4-adapter.jar version 1.0.8 can be downloaded from this location and added to the local repository using the install plugin. For more details of adding a 3rd party jar to local repository, refer to this. Use the below command to install the jar.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=com.aventstack 
    -DartifactId=extentreports-cucumber4-adapter -Dversion=1.0.8 -Dpackaging=jar

In the POM, the version of the adapter dependency needs to be changed to 1.0.8. The extentreports version 4.0.9 dependency needs to be added explicitly to the POM.

The POM for this configuration using version 4.4.0 is located here.

Download 1.0.8 jar

The extentreports-cucumber4-adapter.jar version 1.0.8 can be downloaded from this location and stored in the local machine.

In the POM, the version of the adapter dependency needs to be changed to 1.0.8. Add the scope option and set it to system for the adapter dependency. Also add the systemPath option and set it to the absolute path of the jar file location. The extentreports version 4.0.9 dependency needs to be added explicitly to the POM.

The POM for this configuration using version 4.4.0 is located here.

Cucumber version 4.5.0 to 4.8.0

In version 4.5.0, some of the packages of the source code have been deprecated and new ones added. To get a better understanding of the changes refer to this article. The technique of creating the reports is the same as those mentioned above for the version range 4.21 to 4.4.0. This is meant for the Cucumber versions 4.5.0, 4.5.1, 4.5.2, 4.5.3, 4.5.4, 4.6.0, 4.7.0, 4.7.1, 4.7.2, 4.7.3, 4.7.4, 4.8.0.

The branch that uses the new code structure can be found here. For using the compile from sources method, use this POM instead of the placeholder one. For the install jar method, use this POM. And for the download jar method, use this POM.

Report Activation

First method of activating the report generation is to place extent.properties file in the src/test/resources folder or in the src/test/resources/com/avenstack/adapter folder to be picked up by the adapter. This is ideal for setting up large number of properties. The complete settings for logger and html can be found here. Below examples show the case of the html report.

extent.reporter.html.start=true
extent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html

Second way is to add the required key and value pairs to the System properties. There are again two ways of achieving it.

One way is to add the properties to the configuration section of the Maven Surefire or Failsafe plugin. This is also ideal for setting up large number of properties

<configuration>
    <systemPropertyVariables>
        <extent.reporter.html.start>true</extent.reporter.html.start>
        <extent.reporter.html.out>test-output/HtmlReport/ExtentHtml.html</extent.reporter.html.out>
    </systemPropertyVariables>
</configuration>

Other way is to pass the property key-values in the Maven command. This is useful for small number of properties.

mvn clean install -DargLine="-Dextent.reporter.html.start=true -Dextent.reporter.html.out=test-output/HtmlReport/ExtentHtml.html"

Report Settings

The configurations like report activation and location can be mentioned in the extent.properties or using maven settings as shown in the section above. To change settings like theme, title, encoding etc, a separate xml file eg. extent-config.xml is required. The location for this file eg. html report needs to be mentioned as value for the key extent.reporter.html.config.

extent.reporter.html.config=src/test/resources/extent-config.xml

This xml location key-value pair can also be set using Maven plugin configuration or command line as in the section above. The complete settings for logger and html can be found here.

All that is left to execute the POM and check the reports.

Parallel And\Or Multiple Runner Execution

There is no additional configuration settings required for parallel execution with a single or multiple runners. This is also true for single threaded multiple runner execution.

For parallel execution using JUnit refer here and for TestNG refer here.

Leave a Reply

Your email address will not be published. Required fields are marked *