Cucumber steps 未定义的消息,即使我定义了它们
Cucumber steps undefined messages even though I defined them
当我 运行 Cucumber 测试时,即使在执行了步骤定义之后,控制台 O/P 仍显示步骤未定义。这是为什么?
**Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Mar 21, 2019 1:28:49 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Feature: Automation
Scenario: Login Test [90m# Login.feature:3[0m
[33mGiven [0m[33mUser opens the browser[0m
[33mGiven [0m[33muser is on the login page[0m
[33mThen [0m[33muser logs into the application[0m
[33mThen [0m[33muser is in home page[0m
1 Scenarios ([33m1 undefined[0m)
4 Steps ([33m4 undefined[0m)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^User opens the browser$")
public void user_opens_the_browser() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Given("^user is on the login page$")
public void user_is_on_the_login_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user logs into the application$")
public void user_logs_into_the_application() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user is in home page$")
public void user_is_in_home_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
===============================================
Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
来自FAQ:
“如果 Cucumber 告诉您您的步骤未定义,当您定义了步骤定义时,这意味着 Cucumber 无法找到您的步骤定义。您需要确保指定步骤定义的路径 (粘合路径)正确。
默认情况下,Cucumber-JVM 将在运行程序 class 的包(或子包)中搜索。您还可以明确地告诉 Cucumber-JVM 要搜索哪些包(和子包),使用:
@CucumberOptions(glue = {"<package>", "<package>", "<etc>"})
public class RunCucumberTest{}
需要检查两件事:
在运行文件中检查胶水classes
@CucumberOptions(特征 = {"src/test/resources/features"},
胶水={“mention_package_for_Stepsdef_files”},
plugin = {"漂亮", "html:target/cucumber", "json:target/cucumber/cucumber.json"},
标签 = {"@tag"}
检查您是否已将 stepdef 文件 class(其中写入步骤的定义)声明为 private
或 protected
。应该public
当我 运行 Cucumber 测试时,即使在执行了步骤定义之后,控制台 O/P 仍显示步骤未定义。这是为什么?
**Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Mar 21, 2019 1:28:49 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Feature: Automation
Scenario: Login Test [90m# Login.feature:3[0m
[33mGiven [0m[33mUser opens the browser[0m
[33mGiven [0m[33muser is on the login page[0m
[33mThen [0m[33muser logs into the application[0m
[33mThen [0m[33muser is in home page[0m
1 Scenarios ([33m1 undefined[0m)
4 Steps ([33m4 undefined[0m)
0m0.000s
You can implement missing steps with the snippets below:
@Given("^User opens the browser$")
public void user_opens_the_browser() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Given("^user is on the login page$")
public void user_is_on_the_login_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user logs into the application$")
public void user_logs_into_the_application() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^user is in home page$")
public void user_is_in_home_page() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
===============================================
Suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
来自FAQ:
“如果 Cucumber 告诉您您的步骤未定义,当您定义了步骤定义时,这意味着 Cucumber 无法找到您的步骤定义。您需要确保指定步骤定义的路径 (粘合路径)正确。
默认情况下,Cucumber-JVM 将在运行程序 class 的包(或子包)中搜索。您还可以明确地告诉 Cucumber-JVM 要搜索哪些包(和子包),使用:
@CucumberOptions(glue = {"<package>", "<package>", "<etc>"})
public class RunCucumberTest{}
需要检查两件事:
在运行文件中检查胶水classes
@CucumberOptions(特征 = {"src/test/resources/features"}, 胶水={“mention_package_for_Stepsdef_files”}, plugin = {"漂亮", "html:target/cucumber", "json:target/cucumber/cucumber.json"}, 标签 = {"@tag"}
检查您是否已将 stepdef 文件 class(其中写入步骤的定义)声明为
private
或protected
。应该public