我有一个黄瓜gherkin功能文件如下所示:
Feature: Log in
Scenario Outline: Successful log-in
Given i enter <username>
Given and password <password>
Then I log in
Examples:
| username | password |
| hello | sorry |
| hello | hello |
| hello | goodbye |
| admin | sorry |
| admin | hello |
| admin | goodbye |正如您在上面的用户名和密码表中看到的,有很多重复。我怎样才能消除这种重复?
例如,我可以创建两个特性,如
(1)
Feature: Log in
Scenario Outline: Successful log-in
Given i enter hello
Given and password <password>
Then I log in
Examples:
| password |
| sorry |
| hello |
| goodbye |(2)
Feature: Log in
Scenario Outline: Successful log-in
Given i enter admin
Given and password <password>
Then I log in
Examples:
| password |
| sorry |
| hello |
| goodbye |但这里还是有重复的。
有没有其他方法来删除这个重复。我想要的是:
Feature: Log in
Scenario Outline: Successful log-in
Given i enter <username>
| hello |
| admin |
Given and password <password>
| sorry |
| hello |
| goodbye |
Then I log in但我不确定这类事情是否可能.
PLease帮我..。
我在这里省略了步骤定义,因为它们很容易完成。
发布于 2018-06-13 15:50:43
总之,没有。没有一种方法可以将Examples表中的示例相乘。
但是,还有一种方法可以提高可读性,并提高业务对测试的理解(这正是您真正希望使用BDD风格的测试)。
Background:
Given I am on the login page
Scenario Outline: Logging in with valid passwords
When I attempt to log in as <user_type> with a valid password
Then I should see the <page> page
Examples:
| user_type | page |
| a user | home |
| an admin | admin dashboard |
Scenario Outline: Logging in with invalid passwords
When I attempt to log in as <user_type> with an invalid password
Then I should see the password validation
Examples:
| user_type |
| a user |
| an admin |Background可以消除设置步骤的重复(假设它们在特性中的所有场景中都是相同的),并且如果您将每个场景大纲按它试图实现的目标分组,那么您应该具有更好的可读性,测试的目的是明确表达的。
发布于 2018-06-13 16:34:35
我没有比“凯尔-仙女”更好的答案了。
但为了完整起见,您的场景可能过于简化(这可能掩盖了您的真实意图)。
发布于 2018-07-02 07:34:02
我为它开了一期https://github.com/cucumber/cucumber-js/issues/1105,但它被关闭了:
https://stackoverflow.com/questions/50791957
复制相似问题