我今天写了我的第一个 Cucumber 程序,但它失败了。我写了一个非常基本的,一个简单的场景和它的步骤定义。下面是特征文件代码和步骤定义代码。
步骤定义代码:
import cucumber.api.java.en.When;
import cucumber.api.java.en.Then;
public class Testing_Example1 {
@When("^I am on x page$")
public void i_am_on_x_page() throws Throwable {
System.out.println("I am on xPage");
}
@Then("^I see that element$")
public void i_see_that_element() throws Throwable {
System.out.println("I can see that page");
}
}
功能文件代码:
Feature: Testing
Scenario: s1
When I am on x page
Then I see that element
我还添加了系统变量 - JAVA_HOME 和 maven 变量,并将其链接到 PATH 变量 I 系统变量。
我在 POM 文件中添加了依赖项,例如 Cucumber-Java、Cucumber-Junit 和 selenium,但我的程序失败并说步骤未定义。
输出:
1 Scenarios (1 undefined)
2 Steps (2 undefined)0m0.000s
You can implement missing steps with the snippets below:
@When("^I am on x page$")
public void i_am_on_x_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^I see that element$")
public void i_see_that_element() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
Undefined step: When I am on x page
Undefined step: Then I see that element
Process finished with exit code 0
我想这是因为我的功能文件没有与步骤定义文件链接,但我不明白功能文件没有正确执行并且场景失败的缺失。有这方面知识的人,帮帮忙。
谢谢你!