Search code examples
javaseleniumcucumberextentreports

Extent report is not working in Cucumber 4.7.1


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


Solution

  • 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)