在黄瓜(java版)中,如何将所有步骤与一个"然后"功能?
例如,我希望能够在一个函数中匹配以下所有内容:
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"
我是否需要为每个"或者#34?写一个匹配器?
有没有办法为上面的所有案例编写一个匹配器?
例如,如何将这些组合成一个函数?:
@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);
}
这可能吗?
谢谢!
答案 0 :(得分:3)
根据值列表can grow,您可以使用包含
的要素文件映射到...
Then the response status will be one of the following
| response status |
| 200 |
| 302 |
| 404 |
....
@Then(^the response status will be one of the following$)
public void doResponseStuff(List<String> responses){
// use response codes...
}
使用Cucumber代码
open OUTFILE, '>>', $file_name.".fasta";
答案 1 :(得分:2)
@Reimeus完美答案的替代方案,您也可以在步骤定义中匹配hide()
。
功能定义:
List<Integer>
Java步骤代码:
...
Then the response status will be 200,302,404
...
我认为这两种选择都符合您的要求。希望它有所帮助