java - 如何在 Cucumber-JVM 中用一个 "Then"步骤匹配任意数量的条件?

标签 java cucumber cucumber-jvm cucumber-junit cucumber-java

在 Cucumber(java 版本)中,如何将所有步骤与一个“then”函数匹配?

例如,我希望能够在一个函数中匹配以下所有内容:

Then the response status will be "200"
Then the response status will be "200" or "302"
Then the response status will be "200" or "302" or "404"

我需要为每个“或”编写一个匹配器吗?

有没有一种方法可以为上述所有情况编写一个匹配器

例如,如何将这些组合成一个函数?:

@Then("^the response status should be \"([^\"]*)\"$")
public void the_response_status_should_be(String arg1) throws Throwable {
    System.out.println("** the response status should be "+arg1);
}

@Then("^the response status should be \"([^\"]*)\" or \"([^\"]*)\"$")
public void the_response_status_should_be_or(String arg1, String arg2) throws Throwable {
    System.out.println("** the response status should be "+arg1+" "+arg2);
}

@Then("^the response status should be \"([^\"]*)\" or \"([^\"]*)\" or \"([^\"]*)\"$")
public void the_response_status_should_be_or(String arg1, String arg2, String arg3) throws Throwable {
    System.out.println("** the response status should be "+arg1+" "+arg2+" "+arg3);
}

这可能吗?

谢谢!

最佳答案

鉴于值列表 can grow您可以使用包含

的特征文件映射到 List
...
Then the response status will be one of the following
    | response status | 
    | 200             |
    | 302             |
    | 404             |
....

用 cucumber 代码

@Then(^the response status will be one of the following$)
public void doResponseStuff(List<String> responses){
   // use response codes...
}    

关于java - 如何在 Cucumber-JVM 中用一个 "Then"步骤匹配任意数量的条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39401220/

相关文章:

javascript - jQuery 数据表发送 JSON 搜索参数

ruby-on-rails-3 - 无法让 Cucumber/Capybara 找到单选按钮

testing - 获取Cucumber在Sinatra中使用测试环境

java - 如何在最新的 4.x 版本中将列表传递给 cucumber-jvm stepdef

java - Cucumber 场景断言 DataTable 中的条件

java - XMLEventReader 的当前事件

java - Android:如何使用 ContentProvider 使用 DownloadManager 下载文件到内部存储?

ruby-on-rails-3 - 提升路线未找到错误

selenium - Katalon-将记录的测试脚本导出到Java/Junit

java - 经典键盘/鼠标输入 "converted"进入android触摸输入