Java 线程“main”cucumber.runtime.CucumberException 中的异常:未找到后端

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25923405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:30:48  来源:igfitidea点击:

Exception in thread "main" cucumber.runtime.CucumberException: No backends were found

javaselenium-webdrivercucumber-jvm

提问by Anand Chavan

I am developing my Selenium-JVM framework with Cucumber and while running my first feature got below error.

我正在使用 Cucumber 开发我的 Selenium-JVM 框架,并且在运行我的第一个功能时出现以下错误。

Please help.

请帮忙。

How did I launch the feature -

我是如何启动该功能的 -

  1. Right click on feature file
  2. Select Run As -> Cucumber Feature
  1. 右键单击特征文件
  2. 选择运行方式 -> Cucumber 功能

Immediate Exception -

立即异常 -

Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
    at cucumber.runtime.Runtime.<init>(Runtime.java:78)
    at cucumber.runtime.Runtime.<init>(Runtime.java:67)
    at cucumber.runtime.Runtime.<init>(Runtime.java:63)
    at cucumber.api.cli.Main.run(Main.java:24)
    at cucumber.api.cli.Main.main(Main.java:16)

What I have in code -

我在代码中有什么 -

Launcher.java -

Launcher.java -

package cucumber;

import org.junit.runner.RunWith;

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

@RunWith(Cucumber.class)
@CucumberOptions(format={"pretty","json:target/"} , features="/src/test/java/cucumber/features")
public class Launcher {

}

Feature file -

功能文件 -

Feature: it works demo

  Scenario: First test
    Given this is my step
    When this is my second step
    Then this is my final step

List of Dependencies added to list -

添加到列表中的依赖项列表 -

cucumber-core-1.1.8
cucumber-html-0.2.3
cucumber-java-1.1.8
cucumber-junit-1.1.8
cucumber-jvm-deps-1.0.3
gherkin-2.12.2
hamcrest-all-1.3
junit-4.11
selenium-api-2.42.2
selenium-firefox-driver-2.42.2
selenium-java-2.42.2
selenium-remote-driver-2.42.2
selenium-support-2.42.2

My JVM - 1.7

我的 JVM - 1.7

Only this much is available in project.

项目中只有这么多可用。

Please help.

请帮忙。

采纳答案by hemanto

Make sure you're adding below dependencies for Maven project:

确保为 Maven 项目添加以下依赖项:

You can replace version to the latest or the required version:

您可以将版本替换为最新版本或所需版本:

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>1.2.0</version>
    </dependency>

回答by Seb Rose

This error is thrown when no 'backends' are found on the classpath. There is a 'backend' for each supported language (e.g. cucumber-java, cucumber-groovy etc.)

当在类路径上找不到“后端”时,会抛出此错误。每种支持的语言都有一个“后端”(例如,cucumber-java、cucumber-groovy 等)

It's probably a classpath error, although if cucumber-core and cucumber-java are in the same location that does seem strange.

这可能是一个类路径错误,尽管如果ucumber-core 和cucumber-java 位于同一个位置,这看起来很奇怪。

回答by Bryan Houder

I encountered this same error message when trying to run a Cucumber feature file in Eclipse ("No backends were found. Please make sure you have a backend module on your CLASSPATH").

我在 Eclipse 中尝试运行 Cucumber 功能文件时遇到了同样的错误消息(“未找到后端。请确保您的 CLASSPATH 上有后端模块”)。

What fixed it for me was going into my pom.xml and changing the cucumber-java and cucumber-junit versions away from 1.2.5 (per their documentation) to 1.2.0.

对我来说修复它的是进入我的 pom.xml 并将cucumber-java 和cucumber-junit 版本从1.2.5(根据他们的文档)更改为1.2.0。

I'm not 100% sure if I'm ignoring a real issue by doing this or not. Here is more information about my setup:

我不是 100% 确定我是否通过这样做忽略了一个真正的问题。以下是有关我的设置的更多信息:

  • Windows 10
  • Eclipse Neon (4.6.0)
  • Apache Maven 3.5.0
  • Java 1.8
  • 视窗 10
  • 日食霓虹灯 (4.6.0)
  • Apache Maven 3.5.0
  • 爪哇 1.8

I verified via quick commands that java and maven are installed successfully and running on my machine. I also verified that Maven pulled in the cucumber-java, and cucumber-core jars in my Eclipse project. Odd.

我通过快速命令验证 java 和 maven 已成功安装并在我的机器上运行。我还验证了 Maven 在我的 Eclipse 项目中引入了黄瓜 Java 和黄瓜核心罐。奇怪的。

回答by abhinavgoyal02

You can try the cucumber-java-1.2.4 at https://mvnrepository.com/artifact/info.cukes/cucumber-java/1.2.4.

您可以在https://mvnrepository.com/artifact/info.cukes/cucumber-java/1.2.4尝试黄瓜-java-1.2.4 。

I found that trying a previous version of the same JAR file worked for me. I guess this may solve for other people as well. In case it does not, please add another answer.

我发现尝试使用相同 JAR 文件的先前版本对我有用。我想这也可以解决其他人的问题。如果没有,请添加另一个答案。

Let me know if it worked for you and saved some valuable time :-)

让我知道它是否对您有用并节省了一些宝贵的时间:-)

回答by Arun

Here is the fix: in eclipse projects add the following in the .projectfile

这是修复:在 eclipse 项目中,在.project文件中添加以下内容

<buildSpec>
  ...
  <buildCommand>
 <name>cucumber.eclipse.steps.jdt.stepsBuilder</name>
 <arguments>
 </arguments>
  </buildCommand>
</buildSpec>
<natures>
  ...
  <nature>cucumber.eclipse.steps.jdt.stepsNature</nature>
</natures>

If this did not fix the issue, add the dependency

如果这不能解决问题,请添加依赖项

cucumber-java

黄瓜-java

in the project classpath or change the version of the jar to latest or n-1

在项目类路径中或将 jar 的版本更改为 latest 或 n-1

回答by Raghav

Adding the following dependency I got resolved this issue

添加以下依赖项我解决了这个问题

   <dependency>
       <groupId>io.cucumber</groupId>
       <artifactId>cucumber-java</artifactId>
       <version>4.2.6</version>
   </dependency>

回答by manjoosha

i had pom in my dependency for cucumber-java. Once i removed that worked fine

我对黄瓜 Java 的依赖有 pom。一旦我删除它工作正常

回答by Danish Dogra

You are not providing the path of the step definition class Add glue in the cucumber options may be it will help.

您没有提供步骤定义类的路径在黄瓜选项中添加胶水可能会有所帮助。

**

**

@RunWith(Cucumber.class) @CucumberOptions( 
    features ="Path of the feature file", 
    glue = {"path of step definition class or package "},
    format={"pretty","json:target/"},
    dryRun = true, 
    strict = true,      
    monochrome = true )

**

**