Hot questions for Using Cucumber in extentreports

Top Java Programmings / Cucumber / extentreports

Question:

I'm running tests in parallel on mobile devices using Cucumber and TestNG. My TestNG runner class is given below.

@CucumberOptions(
        features="src/test/resources/features",
        glue={"org.cucumber.stepdefs"},
        plugin = {
        "com.cucumber.listener.ExtentCucumberFormatter:" }, monochrome = true)

public class TestRunner extends BaseTest {

    private static TestNGCucumberRunner testRunner;

    @BeforeClass
    public void setUP() {   
        System.out.println("Thread = " + Thread.currentThread().getId() + " - object hash = " + this.hashCode());
        testRunner = new TestNGCucumberRunner(TestRunner.class);
        ExtentProperties extentProperties = ExtentProperties.INSTANCE;
        extentProperties.setReportPath("output/" + this.hashCode() + "-report.html");
    }

    @Test(description="Tests",dataProvider="features")
    public void setUpClass(CucumberFeatureWrapper cFeature) {
        testRunner.runCucumber(cFeature.getCucumberFeature());
    }

    @DataProvider(name="features")
    public Object[][] getFeatures() {
        return testRunner.provideFeatures();
    }

    @AfterClass
    public static void teardown() {
        testRunner.finish();
    }

}

Which is working as expected - my Cucumber tests are run in parallel on separate threads for each connected device (defined in my testng.xml file).

I'm using ExtentReports to generate reports after each run, though at the moment i'm getting only a single report, where I would like a separate report for each running thread.

What I can't understand is why this is happening. I've added console prints to check if there is an instant of the TestRunner class for each running thread, and indeed there is - my console log after a run contains the following (assuming 2 mobile devices are connected):

Thread = 33 - object hash = 923219673
Thread = 32 - object hash = 280884709

So this is working as i expect, except when it comes to generating the report, only 1 report containing all the test data is created. I was under the assumption that because i am setting the report path to a unique file name in each thread in the setUp() method that a report for each thread should be created?

It seems that when it comes to generating the report that the Cucumber ExtendReport plugin waits for all tests to finish and generates a bulk report by default. Is this correct? And if so, how might i change this?

Below is the main part of my pom.xml file for additional configuration information.

<properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
   <dependencies>
      <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
      <dependency>
         <groupId>info.cukes</groupId>
         <artifactId>cucumber-java</artifactId>
         <version>1.2.5</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-jvm -->
      <dependency>
         <groupId>io.cucumber</groupId>
         <artifactId>cucumber-jvm</artifactId>
         <version>4.2.0</version>
         <type>pom</type>
      </dependency>
      <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
      <dependency>
         <groupId>info.cukes</groupId>
         <artifactId>cucumber-testng</artifactId>
         <version>1.2.5</version>
         <scope>compile</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-picocontainer -->
      <dependency>
         <groupId>info.cukes</groupId>
         <artifactId>cucumber-picocontainer</artifactId>
         <version>1.2.5</version>
         <scope>test</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
      <dependency>
         <groupId>org.seleniumhq.selenium</groupId>
         <artifactId>selenium-server</artifactId>
         <version>3.4.0</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/org.testng/testng -->
      <dependency>
         <groupId>org.testng</groupId>
         <artifactId>testng</artifactId>
         <version>6.11</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
      <dependency>
         <groupId>io.github.bonigarcia</groupId>
         <artifactId>webdrivermanager</artifactId>
         <version>1.7.1</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
      <dependency>
         <groupId>com.aventstack</groupId>
         <artifactId>extentreports</artifactId>
         <version>3.1.5</version>
      </dependency>
      <dependency>
         <groupId>com.vimalselvam</groupId>
         <artifactId>cucumber-extentsreport</artifactId>
         <version>3.0.1</version>
      </dependency>
      <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
      <dependency>
         <groupId>info.cukes</groupId>
         <artifactId>cucumber-junit</artifactId>
         <version>1.2.5</version>
         <scope>test</scope>
      </dependency>
      <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
      <!-- https://mvnrepository.com/artifact/io.appium/java-client -->
      <dependency>
         <groupId>io.appium</groupId>
         <artifactId>java-client</artifactId>
         <version>6.0.0-BETA3</version>
      </dependency>
   </dependencies>
   <build>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
               <source>1.8</source>
               <target>1.8</target>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
               <parallel>tests</parallel>
               <threadCount>10</threadCount>
               <suiteXmlFiles>
                  <suiteXmlFile>testng.xml</suiteXmlFile>
               </suiteXmlFiles>
            </configuration>
         </plugin>
      </plugins>
   </build>

Answer:

@BeforeClass
public void setUP() {   
    System.out.println("Thread = " + Thread.currentThread().getId() + " - object hash = " + this.hashCode());
    testRunner = new TestNGCucumberRunner(TestRunner.class);
    ExtentProperties extentProperties = ExtentProperties.INSTANCE;
    extentProperties.setReportPath("output/" + this.hashCode() + "-report.html");
}

This setup method is invoked twice in parallel. It you are changing setReportPath on ExtentProperties.INSTANCE which is shared between these threads. So the threads are overwriting each others results. You can verify this by printing out the hash of ExtentProperties.INSTANCE.

Question:

When I tried with Cucumber latest version 4.7.1 i.e.,'io.cucumber', with Extent report 3.0 the report is not generated. I have tried with different versions in extent report but still the output is generated properly.

I have tried with different combo versions between Cucumber and Extent Report but still no output. Someone could shed the light over here to bring up the output.

Code:

/**
 * @Author: PriyadarsiniMuthuvel
 * @Created date: 19-08-2019
 * @Project Description: CucumberGradleProject
 **/


import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import managers.FileReaderManager;

import java.io.File;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/resources/SmokeSuite",
        glue= {"stepDef"},
      //  plugin = { "pretty","html:target/cucumber-reports"},
 //  plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},
    // plugin = { "com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html"},
      plugin = { "com.aventstack.extentreportscucumber.adapter.ExtentCucumberAdapter:target/cucumber-reports/report.html"},
        monochrome = true
)
public class testrunner {

    @AfterClass
    public static void writeExtentReport() {

        Reporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));
        Reporter.setSystemInfo("User Name", System.getProperty("user.name"));
        Reporter.setSystemInfo("Time Zone", System.getProperty("user.timezone"));
        Reporter.setSystemInfo("Machine", System.getProperty ("os.name"));
        Reporter.setSystemInfo("Java Version", System.getProperty ("java.version"));
    }
}

Console:

java.lang.NoClassDefFoundError: gherkin/formatter/Reporter at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at com.vimalselvam.cucumber.listener.Reporter.getCurrentScenario(Reporter.java:166) at com.vimalselvam.cucumber.listener.Reporter.assignAuthor(Reporter.java:158) at stepDef.Hooks.BeforeSteps(Hooks.java:39) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at cucumber.runtime.Utils$1.call(Utils.java:26) at cucumber.runtime.Timeout.timeout(Timeout.java:16) at cucumber.runtime.Utils.invoke(Utils.java:20) at cucumber.runtime.java.JavaHookDefinition.execute(JavaHookDefinition.java:65) at cucumber.runner.HookDefinitionMatch.runStep(HookDefinitionMatch.java:16) at cucumber.runner.TestStep.executeStep(TestStep.java:65) at cucumber.runner.TestStep.run(TestStep.java:50) at cucumber.runner.TestCase.run(TestCase.java:42) at cucumber.runner.Runner.runPickle(Runner.java:50) at io.cucumber.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:146) at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:68) at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:23) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at io.cucumber.junit.Cucumber.runChild(Cucumber.java:142) at io.cucumber.junit.Cucumber.runChild(Cucumber.java:65) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) at io.cucumber.junit.Cucumber$RunCucumber.evaluate(Cucumber.java:172) at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27) at org.junit.runners.ParentRunner.run(ParentRunner.java:363) at org.junit.runner.JUnitCore.run(JUnitCore.java:137) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47) at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242) at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70) Caused by: java.lang.ClassNotFoundException: gherkin.formatter.Reporter at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 52 more


Answer:

The Extent report is not supported in Cucumber 4.7.1v. Due to that,we have to work with Extent Report Cucumber Adapter.

In Gradle add the following things Cucumber 4.7.1, Extent Report Cucumber Adapter 1.0.7

Gradle path for Cucumber 4.7.1

compile group: 'com.aventstack', name: 'extentreports-cucumber4-adapter', version: '1.0.7'

In addition to that, manually download the jar and add it to build.gradle as below.

 compile files("src/test/resources/config/extentreports-cucumber4-adapter.jar")

(We have to include both the versions 1.0.7 & 1.0.8 to make it work)

Question:

Using the plugin com.vimalselvam.cucumber.listener.ExtentCucumberFormatter (the only that worked for me), my report is generated but with several errors on the log of intellij

I've tried to generate the report with a scenario not defined (just for the speed). Using more than one plugin, as the plugin

These are the depencies I'm using:

<dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
</dependency>
 <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>3.1.1</version>
</dependency>
<dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>4.0.9</version>
</dependency>
<dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports-cucumber4-adapter</artifactId>
            <version>1.0.7</version>
</dependency>

@CucumberOptions(plugin = {"com.vimalselvam.cucumber.listener.ExtentCucumberFormatter:output/report.html")

@AfterClass
    public static void writeExtentReport() {
Reporter.loadXMLConfig(new File("path/extent-config.xml"));
}

The errors:

log4j:WARN No appenders could be found for logger (freemarker.cache).
log4j:WARN Please initialize the log4j system properly.


java.lang.NoSuchMethodError: com.aventstack.extentreports.reporter.ExtentHtmlReporter.loadXMLConfig(Ljava/io/File;)V

at com.vimalselvam.cucumber.listener.Reporter.loadXMLConfig(Reporter.java:66)
at test.runner.TestRunner.writeExtentReport(TestRunner.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at cucumber.api.junit.Cucumber.run(Cucumber.java:100)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)


java.lang.NullPointerException
    at com.vimalselvam.cucumber.listener.ExtentCucumberFormatter.result(ExtentCucumberFormatter.java:252)...

Answer:

You are using vimal, avenstack and adapter dependencies all together in pom.xml which is not advisable and expected. One shall use vimal or avenstack or both together in specific use case or use adapter dependency only. Please follow below instructions.

Vimal Selvam Library: Below is the required maven dependency and a sample test to demonstrate how configuration set up is done.

Maven Dependency

<dependency>
    <groupId>com.vimalselvam</groupId>
    <artifactId>cucumber-extentsreport</artifactId>
    <version>3.1.1</version>
</dependency>


<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.0.9</version>
</dependency>

Please note that Java 8+ and adding the dependency of ExtentReport v3.1.1+ is mandatory.

Cucumber Runner File

 @RunWith(Cucumber.class)
    @CucumberOptions(
            features = {"src/test/resources/features"},
            glue = {"com.cucumber.stepdefinitions"},
            plugin = {"com.cucumber.listener.ExtentCucumberFormatter:output/report.html"}
            )
    public class RunCukesTest {
        @AfterClass
        public static void teardown() {
            Reporter.loadXMLConfig(new File("src/test/resources/extent-config.xml"));
            Reporter.setSystemInfo("user", System.getProperty("user.name"));
            Reporter.setSystemInfo("os", "Mac OSX");
            Reporter.setTestRunnerOutput("Sample test runner output message");
        }
    }

The above setup will generate the report in output directory with the name of report.html.

Please remove adapter dependency from pom.xml. We shall use vimal/avenstack or extent adapter but not all together.

Extent Adapter: Beauty is, you do not need to write any code any where to generate report this way except from setting adapter in runner below.

Maven Dependency

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports-cucumber4-adapter</artifactId>
    <version>1.0.6</version>
</dependency>

Add the com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter plugin to the runner.

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"})
public class RunCukesTest {
    // ..
} 

Report Output Directory - ../Project Directory/test-output/HtmlReport

Additional Note: In future, we would request you to use Cucumber v>=4.0.0 as you are using pretty old dependency(v1.2.5) of Cucumber.

For doing so, you can add below set of cucumber minimal dependencies.

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>4.2.6</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.2.6</version>
    <scope>test</scope>
</dependency>

Question:

Hi community: I'm facing some issues with trying to implement Extent Reports in Cucumber.

I'm receiving this issue after execution:

java.lang.IncompatibleClassChangeError: Implementing class

    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at cucumber.runtime.io.ResourceLoaderClassFinder.loadClass(ResourceLoaderClassFinder.java:38)
    at cucumber.runtime.io.ResourceLoaderClassFinder.getDescendants(ResourceLoaderClassFinder.java:26)
    at cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:28)
    at cucumber.runtime.Runtime.loadBackends(Runtime.java:99)
    at cucumber.runtime.Runtime.<init>(Runtime.java:66)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:78)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)


Process finished with exit code 255

This is my POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>rodriguitos</groupId>
    <artifactId>zero</artifactId>
    <version>1.0-SNAPSHOT</version>

    <repositories>
    <repository>
        <id>repo.bodar.com</id>
        <url>http://repo.bodar.com</url>
    </repository>
    </repositories>


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <maven.compiler.version>3.7.0</maven.compiler.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <cucumber.version>3.0.2</cucumber.version>
        <selenium.version>3.12.0</selenium.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.6</version>
            <scope>provided</scope>
        </dependency>
       <!-- <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>-->
        <!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java8</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-picocontainer -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>${selenium.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
        <dependency>
            <groupId>io.github.bonigarcia</groupId>
            <artifactId>webdrivermanager</artifactId>
            <version>3.8.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.1.5.RELEASE</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.testng/testng -->
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>${cucumber.version}</version>
            <exclusions>
                <exclusion>
                    <groupId>junit</groupId>
                    <artifactId>junit</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>28.1-jre</version>
        </dependency>
        <!-- REPORTING -->
        <dependency>
            <groupId>com.googlecode.totallylazy</groupId>
            <artifactId>totallylazy</artifactId>
            <version>1.86</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/net.masterthought/cucumber-reporting -->
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>4.11.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.vimalselvam/cucumber-extentsreport -->
        <dependency>
            <groupId>com.vimalselvam</groupId>
            <artifactId>cucumber-extentsreport</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>3.0.2</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.12.2</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports-cucumber3-adapter</artifactId>
            <version>1.0.2</version>
        </dependency>

    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M4</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>src/test/java/resources/testng.xml</suiteXmlFile>
                    </suiteXmlFiles>
                    <testFailureIgnore>true</testFailureIgnore>
                    <includes>
                        <include>**/*ReportsRunner.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.masterthought</groupId>
                <artifactId>maven-cucumber-reporting</artifactId>
                <version>4.5.0</version>
                <executions>
                    <execution>
                        <id>execution</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <projectName>zero</projectName>
                            <outputDirectory>/target/reports/cucumber-reports</outputDirectory>
                            <cucumberOutput>/target/reports/cucumber.json</cucumberOutput>
                            <skippedFails>true</skippedFails>
                            <enableFlashCharts>false</enableFlashCharts>
                            <buildNumber>42</buildNumber>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

I don't know if it was necessary, but this is my runner:

import com.cucumber.listener.ExtentProperties;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import managers.FileReadManager;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = {"src/test/java/features"},
        glue = {"stepdefs"},
        plugin = {"pretty", "com.cucumber.listener.ExtentCucumberFormatter:target/extent-reports/report.html"}
)

public class ExtentsReportsRunner {

    @BeforeClass
    public static void setup() {
        String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
        ExtentProperties extentProperties = ExtentProperties.INSTANCE;
        extentProperties.setReportPath("extent-reports/"+timeStamp.replace(":","_").replace(".","_")+".html");
    }


    @AfterClass
    public static void createExtentReport() {
        Reporter.loadXMLConfig(new File(FileReadManager.FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));
        Reporter.setSystemInfo("user", System.getProperty("user.name"));
        Reporter.setSystemInfo("os", "Mac OSX");
        Reporter.setTestRunnerOutput("Creating Extent Reports...");
    }
}

I know that Extent Reports work with info.cukes instead of io.cucumber and I know this is the right version of java cucumber:

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </dependency>

Can anybody help me, please?


Answer:

You should always use the same version of all cucumber-jvm jars. Now you are using v3.0.2 for most jars (io.cucumber:cucumber-xxx) but v1.2.5 for cucumber-java (info.cukes:cucumber-java). If Extent Reports only work with cucumber-jvm v1.2.5, then you must use v1.2.5 for all cucumber-jvm jars (info.cukes:cucumber-xxx), and also use a info.cukes version of cucumber-jvm-deps.

Question:

I went from Cucumber 1.2.5 to Cucumber 5.6.0. The upgrade went quite smoothly, however my Extent Reports broke. I attempted to upgrade them and use the Cucumber 4 Adapter. The documentation was sparse, and I could not get it to work. So I went and downloaded the Example Implementation. I was able to compile and run it and get reports. I upgraded the example project to Cucumber 4.8.1, and the Extent Reporter to 4, and it ran, but no report was created. I'm at a loss and my google searches have turned up no info.

Here is the original example project: https://github.com/foursyth/extentreports-cucumberN-example

Here is my attempt to update it: https://github.com/dougnoel/extentreports-cucumberN-example/tree/update_to_Cucumber4-adapter

This is the pom.xml:

    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <cucumber.version>4.8.1</cucumber.version>
</properties>
<dependencies>
    <dependency>
        <groupId>com.aventstack</groupId>
        <artifactId>extentreports-cucumber4-adapter</artifactId>
        <version>1.0.12</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
        <scope>test</scope>
    </dependency>
</dependencies>

This is the test runner:

package cucumber.examples.java.calculator;

import org.junit.runner.RunWith;

import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:", "json:target/cucumber-report.json"}
, tags = { "@foo" }
)
public class RunCukesTest {

}

Here is the project I updated to Cucumber 5.6.0 and in which I am trying to keep Extent Reports working: https://github.com/dougnoel/sentinel/tree/93_update_cucumber


Answer:

This question was answered by Grasshopper in a comment. The solution was the fantastic instructions and code that he provided.

In the pom.xml I added:

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>4.1.5</version>
</dependency>

<dependency>
    <groupId>tech.grasshopper</groupId>
    <artifactId>extentreports-cucumber5-adapter</artifactId>
    <version>1.1.0</version>
</dependency>

In my test runner I put:

package cucumber.examples.java.calculator;
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(monochrome = true
    , features = "src/test/java/features"
    , glue = { "stepdefinitions", "com.dougnoel.sentinel.steps" }
    , plugin = {"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}

The final piece was adding a configuration file extent.properties in src/test/resources/ with just three lines:

extent.reporter.html.start=true
extent.reporter.html.out=reports/extent-cucumber-report.html
screenshot.dir=reports/

It now all works as it did before!

Question:

I am trying to customize the extent report which is a third party reporting tool added to my cucumber framework where I want to customize the name of the report.html to "Outputfilename".html which I unable to do as the value of "Outputfilename " is coming from my config file.

here is my testrunner code

    @RunWith(Cucumber.class)
@CucumberOptions(
        features = ".//src//test//java//FeatureList",glue = "stepDefinations",
        plugin = { "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/"+Outputfilename+".html",
                "junit:target/cucumber-results.xml"},
        tags="@smoke",
        monochrome = true
)
public class TestRunner {
    private static final String Outputfilename = FileReader.getInstance().getConfigReader().getReportPath();

I would really appreciate your help.


Answer:

Finally I fixed it-

So basically we need to change the runner class something like this-

package runners;

import PageObjectRep.CF;
import com.cucumber.listener.ExtentProperties;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import managers.FileReader;
import org.apache.log4j.PropertyConfigurator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

import java.io.File;

@RunWith(Cucumber.class)
@CucumberOptions(
        features = ".//src//test//java//FeatureList",glue = "stepDefinations",
        plugin = { "com.cucumber.listener.ExtentCucumberFormatter:",
                "junit:target/cucumber-results.xml"},
        tags="@test",
        monochrome = true
)
public class TestRunner {
    static String ReportName= CF.ReportName(); //function which creates file name as per the execution and saved in string.
    @BeforeClass
    public static void setup() {
        ExtentProperties extentProperties = ExtentProperties.INSTANCE;
        extentProperties.setReportPath("target/cucumber-reports/"+ReportName+".html"); //used same string name to create the file with the same name.
        PropertyConfigurator.configure(".//src//log4j.properties");
    }