我在运行下面的 cucumber 项目时遇到问题。它显示第 7、8、20 和 32 行的错误。
package stepDefinition;
import cucumber.api.java.en.Given;
public class aptitudeTest {
@Given ("I have successfully ([^\"]*)")
public void I have (String str)
{
if (str.equals("registered"))
{
System.out.println("registered Automation");
}
{
System.out.println("unregistered Automation");
}
}
@When ("I enter my valid ([^\"]*)")
public void I enter (String str)
{
if (str.equals("credentials"))
{
System.out.println("credentials Automation");
}
{
System.out.println("details Automation");
}
}
@Then ("I should see the welcome ([^\"]*) him")
public void I should (String str)
{
if (str.equals("welcome"))
{
System.out.println("welcome to your account");
}
{
System.out.println("please enter the correct credential");
}
}
}
下面是功能文件
Scenario:I should see a message when i successfully logged in
Given I have successfully registered
When I enter my valid credentials
Then I should see the welcome message
最佳答案
功能文件以及如何使用“Given”、“When”和“Then”存在许多 2 个问题。
- 方法名称不应包含任何空格。
- 如果要将参数传递给方法,则应将其放在引号中。 前任。我已成功注册应为“我已成功“注册””。此外,相应的方法应注释为“我已成功\”([^\“] *)\” - 你应该在那里有一个转义字符。注册的将是传递的字符串。
关于java - 在 Eclipse 中使用 bdd 运行 cucumber ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43546323/