java - 在 Eclipse 中使用 bdd 运行 cucumber

标签 java eclipse selenium cucumber bdd

我在运行下面的 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 个问题。

  1. 方法名称不应包含任何空格。
  2. 如果要将参数传递给方法,则应将其放在引号中。 前任。我已成功注册应为“我已成功“注册””。此外,相应的方法应注释为“我已成功\”([^\“] *)\” - 你应该在那里有一个转义字符。注册的将是传递的字符串。

关于java - 在 Eclipse 中使用 bdd 运行 cucumber ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43546323/

相关文章:

java - HTTPServletResponse 弄乱了 UTf-8

java - 插件开发: listener to resource change in plugin

java - 如何让其他测试用例等待一段时间,直到测试用例在 TestNG 并行执行中执行操作

java - 在 API 26 或更高版本中使 BroadcastReceiver 在后台工作

java - 自定义项目文件下的 Netbeans 项目 View 中显示的文件

java - 从数据库获取字符串后如何在BIRT中将其转换为整数?

ios - 如何在 XCode 中使键盘配置尽可能接近 Visual Studio 或 Eclipse

java - 如何处理 chrome 驱动程序中的 “Unable to receive message from renderer”?

c# - Chrome驱动Selenium下载位置

java - 从 .txt 文件读取到 JFrame