cucumber - 如何编写场景大纲以捕获单个参数中的对象列表?

标签 cucumber cucumber-jvm gherkin

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

相关文章:

php - Codeception,使用 pageObject 设计模式和小 cucumber 编写验收测试

cucumber - 如何创建 cucumber 数据表?

rspec - capybara 希望页面内容不止一次

ruby - 从 Hook 文件运行 cucumber 测试

ruby - 在 Jenkins 中运行多个 Cucumber 功能

web-services - 如何使用Cucumber来测试我们的设计是否是按层分割的

syntax - 如何在 Gherkin 中屏蔽评论?

ruby-on-rails - 何时在登录过程的 BDD 周期中从 Cucumber 切换到 rspec

javascript - 如何设置 cucumber 环境变量

maven - Dcucumber.options,如何有多个标签