黄瓜扩展报告中的错误(java.lang.ClassNotFoundException:com.cucumber.listener.ExtentCucumberFormatter)

时间:2019-05-22 06:47:28

标签: selenium selenium-webdriver cucumber cucumber-java cucumber-junit

我是硒新手。  我想使用黄瓜生成扩展报告。但是我总是出错

  

“ cucumber.runtime.CucumberException:无法加载插件类:com.cucumber.listener.ExtentCucumberFormatter”

我尝试了每个版本以下代码

POM XML文件:

<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代码:

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");
    }
}

每次我遇到以下错误:

  

cucumber.runtime.CucumberException:无法加载插件类:   com.cucumber.listener.ExtentCucumberFormatter         在Cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:180)         在Cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:165)         在Cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:222)         在cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:205)         在Cucumber.runtime.RuntimeOptions $ ParsedPluginData.addPluginName(RuntimeOptions.java:357)         在Cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:159)         在Cucumber.runtime.RuntimeOptions。(RuntimeOptions.java:90)         在Cucumber.runtime.RuntimeOptions。(RuntimeOptions.java:85)         在Cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:23)         在Cucumber.api.junit.Cucumber。(Cucumber.java:84)         在java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native   方法)         在java.base / jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)         在java.base / jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)         在java.base / java.lang.reflect.Constructor.newInstance(Constructor.java:488)         在org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)         在org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)         在org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)         在org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)         在org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)         在org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)         在org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createUnfilteredTest(JUnit4TestLoader.java:90)         在org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:76)         在org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:49)         在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:525)         在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)         在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)         在org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)       引起原因:java.lang.ClassNotFoundException:com.cucumber.listener.ExtentCucumberFormatter         在java.base / jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)         在java.base / jdk.internal.loader.ClassLoaders $ AppClassLoader.loadClass(ClassLoaders.java:185)         在java.base / java.lang.ClassLoader.loadClass(ClassLoader.java:496)         在Cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:173)         ...另外26个

2 个答案:

答案 0 :(得分:0)

由于您使用的是Cucumber 4版本,因此应该使用插件-“ com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:” 黄瓜Java和黄瓜Junit依赖项应为POM上的4.2.6版本。

有关更多详细信息和示例,请参阅适配器文档-http://extentreports.com/docs/versions/4/java/cucumber4.html

答案 1 :(得分:0)

问题陈述分析-

  • 在pom.xml中一起使用 vimal,avenstack adapter依赖,这是不可取和不可取的。一个人应在特定用例中同时使用vimal或avenstack或两者一起使用,或仅使用适配器依赖项。请按照以下说明进行操作。

  • 从info.cukes和io.cucumber依赖关系中添加直接和传递依赖关系。这样做可能导致不可预测的结果。现在开始吧。

虚拟Selvam库:以下是必需的maven依赖项和一个示例测试,以演示如何完成配置设置。

Maven依赖

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

请注意,必须安装 Java 8 + ,并添加 ExtentReport v3.1.1 + 的依赖项。

黄瓜跑步者文件

 @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");
        }
    }

以上设置将在输出目录中生成名为report.html的报告。

请从pom.xml中删除适配器依赖项。我们将使用vimal / avenstack或扩展适配器,但不能一起使用。

扩展适配器:美丽的是,除了在下面的运行器中设置适配器之外,您不需要在任何地方编写任何代码来生成报告。

Maven依赖

<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目录/ test-output / HtmlReport

附加说明::将来,我们会要求您使用Cucumber v> = 4.0.0 ,因为您使用的是非常老的依赖项( v1.2.5 )。

为此,,您可以添加以下一组黄瓜最小依赖项。

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