在编写 cucumber 场景大纲测试用例时,有时我需要一个占位符来保存一组数据而不是一个。请参阅下面的伪示例:
Scenario Outline: example
Given I have <input_1>
When I choose <input_2>
Then I should receive <result_list> //instead of a single result
Examples:
| input_1 | input_2 | result |
| input_1_case_1 | input_2_case_1 | result_1_case_1_part_1 |
| | | result_1_case_1_part_2 |
| | | result_1_case_1_part_3 |
在上面的示例中,我的“结果”需要捕获每个 input_1 和 input_2 参数的对象列表。但是通过上面的写法,cucumber不会将最后一条语句编译为类似:
@Then("....")
public void i_should_receive(Datatable or list of object) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
如何编写我的 cucumber 脚本来实现我想要的?
谢谢。
最佳答案
Scenario Outline: example
Given I have <input_1>
When I choose <input_2>
Then I should receive <result_list> //instead of a single result
Examples:
| input_1 | input_2 | result
| input_1_case_1 | input_2_case_1 | result_1_case_1_part_1,result_1_case_1_part_2,result_1_case_1_part_3 |
然后在您的步骤定义中
@Then("....")
public void i_should_receive(String result) throws Throwable {
List<String> items = Arrays.asList(str.split("\\s*,\\s*"));
}
关于cucumber - 如何编写场景大纲以捕获单个参数中的对象列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36111035/