Extentreport support for Cucumber-JVM 4.0 (io.cucumber)

流过昼夜 提交于 2020-12-06 15:38:17

问题


I am trying to migrate my Cucumber automation project from cucumber (info.cukes ) to cucumber (io.cucumber)

During this process, i having trouble with migrating extend reports. Could you please help me with what I am missing?

dependency:

    <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.2.6</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-junit -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.2.6</version>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-core -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>4.2.6</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-html -->
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-html</artifactId>
            <version>0.2.7</version>
        </dependency>
<dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.26-incubating</version>
        </dependency>


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

        <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports -->
        <dependency>
            <groupId>com.aventstack</groupId>
            <artifactId>extentreports</artifactId>
            <version>4.0.9</version>
        </dependency>

Runner class:

package CucumberWithAfterStep.AfterStepPOC;
import java.io.File;
import org.junit.AfterClass;
import org.junit.runner.RunWith;
import com.cucumber.listener.Reporter;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/features", glue = { "testSteps" }, plugin = { "pretty",
                                "html:target/cucumber", "json:target/cucumber.json" , "com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/report.html" },
                                monochrome = true, 
                                tags = {"@WAC003 "}, dryRun = false)

public class MainRunnerTest {

 @AfterClass
 public static void writeExtentReport() {
     Reporter.loadXMLConfig(new File(FileReaderManager.getInstance().getConfigReader().getReportConfigPath()));
    }
 }

Error:

cucumber.runtime.CucumberException: Couldn't load plugin class: com.cucumber.listener.ExtentCucumberFormatter. It does not implement

cucumber.api.Plugin at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:176) at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:163) at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:220) at cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:203) at cucumber.runtime.RuntimeOptions$ParsedPluginData.addPluginName(RuntimeOptions.java:386) at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:165) at cucumber.runtime.RuntimeOptions.(RuntimeOptions.java:108)


回答1:


There are 2 ways of implementing extent report in Cucumber

1. Using Cucumber-JVM 4 adapter for Extent Framework(extentreports-cucumber4-adapter) & below are the steps to implement -

Add adapter dependency under POM.XML

<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

2. Adding aventstack dependency under POM.XML

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

In this workflow, Do not Add the com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter plugin to the runner.




回答2:


I had the same issue. you can use the following combination of dependencies, Cucumber-core 4.2.0 Cucumber-java 4.2.0 Cucumber-junit 4.2.0 extentreports-cucumber4-adapter 1.0.7

Please note Cucumber-extntsreport which is developed by vimalselvam is not supporting cucumber version 4. Because cucumber 4 is using event based reporting, not the formatter. so remove this dependency. cucumber-extentsreport 3.0.2



来源:https://stackoverflow.com/questions/55763356/extentreport-support-for-cucumber-jvm-4-0-io-cucumber

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!