2

我正在尝试使用 Junit cucumber 为我的测试运行生成范围报告,但出现错误

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

我的错误跟踪如下-:

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:179)
    at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:166)
    at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:223)
    at cucumber.runtime.formatter.PluginFactory.isFormatterName(PluginFactory.java:201)
    at cucumber.runtime.RuntimeOptionsFactory.addPlugins(RuntimeOptionsFactory.java:94)
    at cucumber.runtime.RuntimeOptionsFactory.buildArgsFromOptions(RuntimeOptionsFactory.java:41)
    at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:26)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:74)
    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 org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:87)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:73)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:46)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:522)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)

我的 Pom.xml 具有以下依赖项-:

<dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>2.3.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>


        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>2.3.1</version>
        </dependency>

        <dependency>
            <groupId>com.beust</groupId>
            <artifactId>jcommander</artifactId>
            <version>1.27</version>
        </dependency>

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



        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.13</version>
            <scope>test</scope>
        </dependency>

        <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> 
            <version>3.8.1</version> </dependency> 

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




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


        <dependency>
            <groupId>com.relevantcodes</groupId>
            <artifactId>extentreports</artifactId>
            <version>2.41.2</version>
        </dependency>


        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-jvm-deps</artifactId>
            <version>1.0.3</version>
            <scope>provided</scope>
        </dependency>


        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>gherkin</artifactId>
            <version>2.7.3</version>
        </dependency>

我的 Runner 课程如下-:

package com.cumberpr2.Runner;

import java.io.File;

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

import com.cucumber.listener.ExtentProperties;
import com.cucumber.listener.Reporter;

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

@RunWith(Cucumber.class)
@CucumberOptions(features= {"src/test/java/com/cumberpr2/First/feature"},glue= {"com/cumberpr2/step"},
monochrome=true,tags= {"@bvt,@sanity"},plugin={"com.cucumber.listener.ExtentCucumberFormatter:target/cucumber/report1.html"} 
)
//{"pretty","html:target/cucumber","com.cucumber.listener.ExtentCucumberFormatter"}
public class Runner1 {

     @AfterClass
        public static void teardown() {
            Reporter.loadXMLConfig(new File("/src/test/java/com/cumberpr2/step/Extent-Config.xml"));

            Reporter.setSystemInfo("os", "windows OSX");
            Reporter.setTestRunnerOutput("Sample test runner output message");
        }

    /* @BeforeClass
     public static void setup() {
         ExtentProperties extentProperties = ExtentProperties.INSTANCE;
         extentProperties.setReportPath("output/myreport.html");
         extentProperties.setExtentXServerUrl("http://localhost:1337");
         extentProperties.setProjectName("MyProject");
     }*/


}

我的文件夹结构如下 -: [1]: https://i.stack.imgur.com/ek06R.png

[在此处输入图片描述][1]

4

2 回答 2

4

在寻找同样发生在我身上的这个问题的解决方案很多天之后,我发现了原因(至少对我有用)。显然,插件 com.cucumber.listener.ExtentCucumberFormatter 或 com.vimalselvam.cucumber.listener.ExtentCucumberFormatter (对于 cucumber-extentreports 版本 3.1.1+)仅适用于 info.cukes 包的黄瓜。

<! - https://mvnrepository.com/artifact/info.cukes/cucumber-java ->
<dependency>
<groupId>info.cukes</ groupId>
<artifactId>cucumber-java</artifactId>    
<version>1.2.5</ version>
</dependency>

要将 ExtentReports 与最新的 cucumber 版本(从 2.XX 版本开始的 io.cucumber 包)一起使用,您需要添加 cucumber-adapter 插件。

对于每个 X 版本的 Cucumber,都有一个适配器,例如对于 Cucumber 版本 4.XX,需要 extentreports-cucumber4-adapter 依赖项。

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

          

在 Runner 类中,您应该替换插件:

“com.cucumber.listener.ExtentCucumberFormatter:”

经过

“com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:”

有关将 cucumber 4 与范围报告一起使用的示例,请访问我找到的 GitHub 链接:

https://github.com/foursyth/extentreports-cucumber4-example

对于版本 2.XX 和 3.XX 遵循与 4.XX 相同的原则

所有版本的ExtentReport设置规范链接:

http://extentreports.com/documentation/

希望这可以帮助。

于 2019-05-13T16:31:55.863 回答
1

建议将您的黄瓜 v 升级到 4.xx这样做不仅可以解决您的错误,而且您还可以在并行执行期间生成合并报告,而无需手动创建跑步者。

在 Cucumber 中有两种实现范围报告的方法:

1. 为 Extent 框架使用 Cucumber-JVM 4 适配器(extentreports-cucumber4-adapter) - 美丽之处在于,除了在下面的运行器中设置适配器之外,您不需要在任何地方编写任何代码来生成报告。

在 POM.XML 下添加适配器依赖

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

将 com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter 插件添加到运行器。

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

报告输出目录 - ../Project Directory/test-output/HtmlReport

2.在POM.XML下添加aventstack依赖

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

在此工作流程中,请勿将 com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter 插件添加到运行器。

于 2019-05-13T18:00:34.863 回答