“ java.lang.NoClassDefFoundError:gherkin / formatter / Reporter”执行TestRunner.java文件时出错

时间:2019-04-03 16:16:21

标签: cucumber gherkin extentreports

以下是使用过的依赖项:

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

<dependency>
<groupId>com.vimalselvam</groupId>
<artifactId>cucumber-extentsreport</artifactId>
<version>3.0.2</version>
</dependency>
        <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>gherkin</artifactId>
    <version>4.1.3</version>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm</artifactId>
    <version>4.2.6</version>
    <type>pom</type>
</dependency>
<dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>4.2.6</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-jvm-deps</artifactId>
    <version>1.0.6</version>
    <scope>provided</scope>
</dependency>


<!-- Extent Report >
<dependency>
    <groupId>com.relevantcodes</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.41.2</version>
</dependency>

<dependency>
    <groupId>net.masterthought</groupId>
    <artifactId>cucumber-reporting</artifactId>
    <version>4.5.1</version>
</dependency-->

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

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


<!-- Selenium Dependancy-->
<dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

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

        <dependency>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>4.2.6</version>
    <scope>test</scope>
</dependency>

Here are dependencies which has used

如果您没有在范围报告中包括黄瓜插件,那么它可以工作,但是当我包括黄瓜插件时,它会引发小黄瓜格式化错误

与Gherkin一起使用插件时显示以下错误:

java.lang.NoClassDefFoundError: gherkin/formatter/Reporter
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:171)

。 。

Caused by: java.lang.ClassNotFoundException: gherkin.formatter.Reporter
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 40 more



If you are not including cucumber plugin with extent report then it works but when i have included cucumber plugin then it throws gherkin formatter error

为此请帮帮我。

下面是黄瓜课:

@RunWith(Cucumber.class)
@CucumberOptions(
    plugin = {"com.cucumber.listener.ExtentCucumberFormatter:./Cucumber-Reports/Cucumber-Report.html","rerun:target/rerun.txt"},
    monochrome=true,
    features = {"./src/Features"},
    tags = {"@Regression"},
    glue={"stepDefinitions"},   
    dryRun = false,
    strict = true
) 

1 个答案:

答案 0 :(得分:0)

您的extentreports版本为2.41.2,并且仅适用于版本3或更高版本。

这是您应该更改版本的依赖项:

<dependency>
    <groupId>com.aventstack</groupId>
    <artifactId>extentreports</artifactId>
    <version>2.41.2</version> //You should update it to 3 or above.
</dependency>