0
votes

I am new in selenium. I want to generate extend report using cucumber. But I am always getting error

"cucumber.runtime.CucumberException: Couldn't load plugin class: com.cucumber.listener.ExtentCucumberFormatter"

I tried every version Below code I have

POM XML File:

<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>CucumberFramwork</groupId>
    <artifactId>ExtendReport</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>ExtendReport</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>




    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </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>3.1.1</version>

        </dependency>

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



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

        <!-- >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 -->

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

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm</artifactId>
            <version>1.2.5</version>
            <type>pom</type>
        </dependency>

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.5</version>
            <scope>test</scope>
        </dependency>


    </dependencies>



    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Java Code:

package runners;

import java.io.File;

import org.junit.AfterClass;
import org.junit.runner.RunWith;

import com.vimalselvam.cucumber.listener.Reporter;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/functionalTests", 
                 glue = { "stepDefinitions" }, plugin = {
        "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html" }, 
                 monochrome = true)
public class TestRunner {
    @AfterClass
    public static void writeExtentReport() {
        try {
            Reporter.loadXMLConfig(new File("C:\\Software\\WprkSpace\\ExtendReport\\Configs\\extent-config.xml"));
        }
     catch (Exception e) {
        e.printStackTrace();
        }
        //Reporter.loadXMLConfig("/ExtendReport/Configs/extent-config.xml");
    }
}

Every time I am geting below error:

cucumber.runtime.CucumberException: Couldn't load plugin class: com.cucumber.listener.ExtentCucumberFormatter at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:180) at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:165) at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:222) at cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:205) at cucumber.runtime.RuntimeOptions$ParsedPluginData.addPluginName(RuntimeOptions.java:357) at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:159) at cucumber.runtime.RuntimeOptions.(RuntimeOptions.java:90) at cucumber.runtime.RuntimeOptions.(RuntimeOptions.java:85) at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:23) at cucumber.api.junit.Cucumber.(Cucumber.java:84) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488) at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) 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:26) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209) Caused by: java.lang.ClassNotFoundException: com.cucumber.listener.ExtentCucumberFormatter at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496) at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:173) ... 26 more

2
could anyone have look? it is urgentHamesh

2 Answers

0
votes

Problem Statement Analysis -

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

  • Adding direct & transitive dependencies together from info.cukes & io.cucumber dependencies. Doing so can cause unpredictable outcome. Now let's move.

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>
0
votes

Since you are using cucumber 4 version, you should be using the plugin - "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:" cucumber-java & cucumber-junit dependency should be 4.2.6 version on your POM.

see adapter documentation- http://extentreports.com/docs/versions/4/java/cucumber4.html for more details & examples.