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

问题描述 投票:0回答:1

以下是使用的依赖项:

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

如果你没有包含范围报告的黄瓜插件然后它的工作,但当我包括黄瓜插件然后它抛出小黄瓜格式化程序错误

使用Plugin with 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
) 
cucumber gherkin extentreports
1个回答
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>  
© www.soinside.com 2019 - 2024. All rights reserved.