在 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/