Scenario Outline关键字可用于使用不同的值组合多次运行同一方案。
当参数是表格时,如何使用场景大纲来简化多个场景。
Scenario: 1 row
Given I import data to a table
| col1 | col2 |
| value1-1 | value1-2 |
When I execuate the logic1
Then I can get data
| result_col1 | result_col2 |
| result-value1-1 | result-value1-2 |
Scenario: 2 rows
Given I import data to a table
| col1 | col2 |
| value1-1 | value1-2 |
| value2-1 | value2-2 |
When I execuate the logic1
Then I can get data
| result_col1 | result_col2 |
| result-value1-1 | result-value1-2 |
Scenario: 3 rows
Given I import data to a table
| col1 | col2 |
| value1-1 | value1-2 |
| value2-1 | value2-2 |
| value3-1 | value3-2 |
When I execuate the logic1
Then I can get data
| result_col1 | result_col2 |
| result-value1-1 | result-value1-2 |
| result-value3-1 | result-value3-2 |发布于 2019-08-30 06:04:05
您在列中使用相同的步骤和相同的期望值。
您可以使用Scenario Outline进行简化,如下所示:
Scenario Outline: Example Scenario Outline
Given that the user import the following data to a table
| Col1 | Col2 |
| <Col1> | <Col2> |
When the user perform the logic action
Then I can get data "<Result_col1>" and "<Result_col2>"
Examples:
| Id | Scenario | Col1 | Col2 | result_col1 | result_col2 |
| 1 | value1-1 | value1-1 | value1-2 | result-value1-1 | result-value1-2 |
| 2 | value2-1 | value2-1 | value2-2 | result-value2-1 | result-value2-2 |注意:在您的代码中,您可以将值作为列表或数据表。使用Jackson,您可以创建不同的DTO,并映射steps和Dto类中的数据
@Given("^that the user import the following data to a table$")
public void that_the_user_import_the_following_data_to_a_table(DataTable yourClassExampleDTO) throws Throwable {
List<YourClassExampleDTO> lstYourClassExampleDTO = yourClassExampleDTO.asList(YourClassExampleDTO.class);
int lstSize = lstYourClassExampleDTO.size();
for (int i = 0; i < lstSize; i++) {
lstYourClassExampleDTO.get(i);
}
}https://stackoverflow.com/questions/57655888
复制相似问题