【问题标题】:Facing error "cucumber.runtime.CucumberException: No backends were found."面临错误“cucumber.runtime.CucumberException:未找到后端。”
【发布时间】:2020-07-26 11:02:46
【问题描述】:

我正在使用 Cucumber 设置处理 Selenium,运行 TestRunner 文件时遇到错误。

cucumber.runtime.CucumberException:未找到后端。请确保您的 CLASSPATH 上有一个后端模块。

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>Automation</groupId>
  <artifactId>Cucumber</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>Cucumber</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>

</dependency>


<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>


    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>      
    </dependency>
  </dependencies>
</project>

我已将功能文件映射到 StepDefinition 文件,如下所示 功能文件 特点:登录功能

场景:首页默认登录 给定用户在主页上 当用户使用有效凭据登录应用程序时 然后用户应该登录到应用程序和登录页面应该显示给用户

步骤定义文件

package stepDefenition;

import org.junit.runner.RunWith;
import cucumber.api.junit.Cucumber;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;

@RunWith(Cucumber.class)
public class StepDefenition {

    @Given("^User is on Home page$")
    public void user_is_on_home_page() throws Throwable {
        System.out.println("User is on Home Page");
    }

    @When("^User logs into application with valid credentials$")
    public void user_logs_into_application_with_valid_credentials() throws Throwable {
        System.out.println("User enters valid credentials and clicks on submit");

    }

    @Then("^User should be logged into application and landing page should be displayed to user$")
    public void user_should_be_logged_into_application_and_landing_page_should_be_displayed_to_user() throws Throwable {
         System.out.println("User logged in successfully and landing page is displayed to user  with all the details");
    }

}

测试运行文件:

package cucumberOption;

import org.junit.runner.RunWith;

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

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/test/java/features",
        glue="stepDefenition")

public class TestRunner {   

}

我正在使用版本:

  • Eclipse 的 Neon.3 版本 (4.6.3)
  • Natural 0.7.6 Cucumber 插件
  • Maven 版本:Apache Maven 3.6.3
  • Java 版本:Java 版本“1.8.0_241”

项目结构

我尝试更改 java 和 Junit 的版本并添加 Io.cucumber 依赖项,但没有任何效果。

在项目构建路径中添加了 java 1.8 jdk。

我已经查看了有关此类问题的所有先前线程。

【问题讨论】:

标签: java eclipse cucumber


【解决方案1】:

我不明白你为什么在步骤 def 类中使用 @RunWith 注释。由于 cucumber 将自动通过 cucumberRunner 运行它,因此您可以使用任何 @RunWith 注释从 Runner 类或通过功能文件(场景级别或整个功能文件)执行您的测试。可能这是您的错误的原因 - 请参阅以下异常:

cucumber.runtime.CucumberException:

用@RunWith(Cucumber.class) 注释的类不能定义任何 步骤定义或挂钩方法。他们的唯一目的是作为 JUnit 的入口点。应定义步骤定义和挂钩 在他们自己的班级里。这允许它们跨功能重用。 违规类:com.abc.StepDefs.FWFeatureTestSteps 类(例如)。

另外你不需要在 pom 中有单独的 junit 依赖,只要你想让 cucumber 完成工作,只有 cucumber-junit 就足够了。 注意:不要混合使用 io.cucumber 和 info.cukes,使用它们中的任何一个。将两者混合也会导致同样的异常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2015-06-22
    • 2012-09-15
    相关资源
    最近更新 更多