【发布时间】: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。
我已经查看了有关此类问题的所有先前线程。
【问题讨论】:
-
你的项目有很多问题。考虑使用cucumber.io/docs/guides/10-minute-tutorial从头开始