【发布时间】:2016-12-15 06:49:21
【问题描述】:
我是 Cucumber 的新手。我想测试两种登录场景:
- 使用有效凭据,用户应该能够成功登录
- 用户名和密码为空,用户无法登录
对于上述场景,我有以下代码:
Scenario Outline: Test login with valid credentials
Given Open firefox and start application
When I enter "<username>" and "<password>"
Then User should be able to login successfully
Examples:
| username | password |
| ro | mech |
Scenario Outline: Test login with empty credentials
Given Open firefox and start application
When I enter "<username>" and "<password>" (this shows a warning)
Then User should be not able to login
Examples:
| username | password |
| | |
在 java 文件中我有以下代码:
@When("^I enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void I_enter_and_(String username, String password) throws Throwable {
driver.findElement(By.id("ember629")).sendKeys(username);
driver.findElement(By.id("ember640")).sendKeys(password);
}
我的问题是场景 2 显示警告消息:
Step 'I enter "<username>" and "<password>"' does not have a matching glue code
这是否意味着对于每个场景,例如有效、空和无效的凭据,我都需要编写一个单独的 java 函数?我不能使用相同的java函数吗:
public void I_enter_and_(String username, String password)
适用于所有场景?如果我运行功能文件,我会得到以下输出:
You can implement missing steps with the snippets below:
@When("^I enter \"([^\"]*)\" and \"([^\"]*)\"$")
public void i_enter_and(String arg1, String arg2) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
有没有办法复用java函数I_enter_and_?
【问题讨论】:
-
你用什么类来运行?