是否可以在场景大纲中编写两组不同的示例

时间:2016-11-10 13:59:53

标签: cucumber

要求是创建三个用户,然后创建模板/文件以添加这三个用户

我可以在单一场景大纲中实现这一目标吗?

Scenario Outline: Create users and load to a template
Given I create an user <username>
And the password as <password>
And the description as <description>

Example: 
| username |   password    |    description  |

|  user1   | pwd1          | user1creation   |

|  user2   | pwd2          | user2creation   |

|  user3   | pwd3          | user3creation   |

When user create a template ??????

有人可以建议如何编写模板创建步骤并将用户名作为参数传递吗?

1 个答案:

答案 0 :(得分:0)

场景可以这样写:

  Scenario Outline: Create users and load to a template
Given I have the following users:
  | username    | password    | description    |
  | <username1> | <password1> | <description1> |
  | <username2> | <password2> | <description2> |
  | <username3> | <password3> | <description3> |
When I create template for users:
  |  username   |
  | <username1> |
  | <username2> |
  | <username3> |
Then users should be added to template
Examples:
  | username1 | password1 | description1  | username2 | password2 | description2  | username3 | password3 | description3  |
  | user1     | pwd1      | user1creation | user2     | pwd2      | user2creation | user3     | pwd3      | user3creation |

或者作为替代方案而不使用场景大纲:

  Scenario: Create users and load to a template
Given I have the following users:
  | username | password | description   |
  | user1    | pwd1     | user1creation |
  | user2    | pwd2     | user2creation |
  | user3    | pwd3     | user3creation |
When I create template for users:
  | username |
  | user1    |
  | user2    |
  | user3    |
Then users should be added to template

在Given步骤的两种情况下,都应该定义用户,在步骤定义中创建并放入一些共享的Map,其中在步骤时,可以将它们引出并添加到模板中。