[英]How to match any number of conditions with one “Then” step in Cucumber-JVM?
在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);
}
這可能嗎?
謝謝!
鑒於值列表可以增長,您可以使用包含以下內容的功能文件映射到List
...
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...
}
@Reimeus好答案的替代方法,您也可以在步驟定義中匹配List<Integer>
。
功能定義:
...
Then the response status will be 200,302,404
...
Java步驟代碼:
@When("^the response status will be (.*)$")
public void the_response_status_should_be(List<Integer> statusList) throws Throwable {
//...
}
我認為這兩種選擇均符合您的要求。 希望能幫助到你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.