黄瓜依赖问题-无法加载插件类

时间:2019-05-24 04:27:16

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

我是黄瓜可扩展代码的新手,需要帮助。我正在使用Java 8和Maven,并希望生成黄瓜可扩展报告。但是每次我遇到以下错误时:

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

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>4.11</version>
        </dependency>

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

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

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

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.5</version>
        </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>
        </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>

赛跑者职业代码:

package runners;

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/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: Couldn't load plugin class: com.cucumber.listener.ExtentCucumberFormatter. It does not implement cucumber.api.Plugin
    at cucumber.runtime.formatter.PluginFactory.loadClass(PluginFactory.java:178)
    at cucumber.runtime.formatter.PluginFactory.pluginClass(PluginFactory.java:165)
    at cucumber.runtime.formatter.PluginFactory.getPluginClass(PluginFactory.java:222)
    at cucumber.runtime.formatter.PluginFactory.isStepDefinitionReporterName(PluginFactory.java:205)
    at cucumber.runtime.RuntimeOptions$ParsedPluginData.addPluginName(RuntimeOptions.java:357)
    at cucumber.runtime.RuntimeOptions.parse(RuntimeOptions.java:159)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:90)
    at cucumber.runtime.RuntimeOptions.<init>(RuntimeOptions.java:85)
    at cucumber.runtime.RuntimeOptionsFactory.create(RuntimeOptionsFactory.java:23)
    at cucumber.api.junit.Cucumber.<init>(Cucumber.java:56)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:488)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)

2 个答案:

答案 0 :(得分:0)

POM分析说-

  • 您要保留不同范围的库来创建不建议也不希望的报告。我们将根据需求使用特定的一组集合。
  • 您正在使用黄瓜的相当老的依赖项( info.cukes v1.2.5
  • 您的pom.xml同时具有直接和传递依赖项

首先让我们对这些库的基本了解来创建范围报告

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

Maven依赖

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

请注意,必须使用 Java 8 + 并添加 ExtentReport v3.1.1 + 的依赖项。为此,请将以下内容粘贴到pom.xml中: / p>

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

黄瓜跑步者文件

 @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的报告。

2。扩展适配器:美丽的是,您无需在任何以这种方式生成报告的地方编写任何代码,除非在下面的运行器中设置适配器。

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 ,因为您正在使用Cucumber的相当老的依赖项( 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>

第二考虑到不使用扩展适配器的情况,在POM.XML **下添加了以下扩展依赖。

<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.5</version>
</dependency> 

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

最后一个 Hooks类,我们在其中编写针对每种情况执行的扩展区代码。

公共类挂钩{

private final static Logger log = Logger.getLogger(Hooks.class);
static volatile int x = 0;

@Before
public void setUpScenario(Scenario scenario){
    ExtentTestManager.startTest("Scenario No . " + (x = x + 1) + " : " + scenario.getName());
    ExtentTestManager.getTest().log(Status.INFO, "Scenario No . "+ x + " Started : - " + scenario.getName());
}

@After
public void afterScenario(Scenario scenario){
    String videoFile= Utility.stopAUTTestRecorder();
    try{
        if(scenario.isFailed()){
           ExtentTestManager.addScreenShotsOnFailure();
            //------------------------- Attaching video in the Report -------------------------
            String failedTestVideo = "<a href=\"" + videoFile + "\">Download Failed Test Case Video</a>";
            ExtentTestManager.embedVideoLink(failedTestVideo);
            //scenario.write(failedTestVideo);
        }
        }
        ExtentManager.getReporter().flush();
    }
  }

答案 1 :(得分:0)

尝试在下面的相同版本中使用这2个依赖项

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

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

更多信息在这里:

extent-report-plugin-for-cucumber