[英]Undefined Step definitions in Cucumber Java
I added the login steps in Login class.我在登录 class 中添加了登录步骤。 But when I run the scenario from the Login.feature file I still get undefined steps error.但是当我从 Login.feature 文件运行场景时,我仍然得到未定义的步骤错误。
Login class登录 class
package stepDefinitions;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
public class Login {
@Given("I am on the login page")
public void ı_am_on_the_login_page() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
@When("I enter a correct e-mail address")
public void ı_enter_a_correct_e_mail_address() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
@And("I enter a correct password")
public void ı_enter_a_correct_password() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
@And("I click on login button")
public void ı_click_on_login_button() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
@Then("I should be presented with successful login message")
public void ı_should_be_presented_with_successful_login_message() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
}
This is my Login.feature file这是我的 Login.feature 文件
Feature: Login page
Scenario: Successful login test
Given I am on the login page
When I enter a correct e-mail address
And I enter a correct password
And I click on login button
Then I should be presented with successful login message
pom.xml file pom.xml 文件
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>Segmentify_Project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.4</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.3.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>7.3.3</version>
</dependency>
</dependencies>
</project>
This is the project format这是项目格式
enter image description here在此处输入图像描述
I receive the following error when I run the scenario from Login.feature从 Login.feature 运行场景时收到以下错误
Step undefined You can implement this step and 4 other step(s) using the snippet(s) below:步骤未定义您可以使用以下代码段实现此步骤和其他 4 个步骤:
@Given("I am on the login page")
public void ı_am_on_the_login_page() {
// Write code here that turns the phrase above into concrete actions
throw new io.cucumber.java.PendingException();
}
I got an error similar to this.我遇到了类似的错误。 I tried different solution, like edit configuration.我尝试了不同的解决方案,例如编辑配置。 But when i create runner class and run it, the feature started working without any problem.但是当我创建跑步者 class 并运行它时,该功能开始工作没有任何问题。
My runner class我的跑步者 class
@RunWith(Cucumber.class)
@CucumberOptions(features ="C:\\Users\\user1\\Desktop\\Selenium\\com.cucumber\\src\\test\\resources\\features"
,glue = "stepDefinition")
public class testRunner {
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.