Gherkin table - 删除重复

Gherkin table - remove repetition

我有如下所示的黄瓜小黄瓜功能文件:

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 |

正如您在上面看到的用户名和密码table,有很多重复。我怎样才能消除这种重复?

例如,我可以创建两个功能,例如

(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

但我不确定上面的事情是否可能...

请帮助我...

我在这里省略了步骤定义,因为它们很容易做到。

简而言之,没有。 Examples table.

中的示例无法相乘

但是,还有一种替代方法可以提高可读性并增加对业务测试的理解(这是您真正想要使用 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's 可以消除设置步骤的重复(假设它们在一个功能的所有场景中都是相同的)并且如果您根据它试图实现的目标对每个场景大纲进行分组, 你应该有更多的整体可读性,明确表达测试的意图。

没有比@kyle-fairns 更好的答案了。

但为了完整起见,因为您的场景可能过于简单化(这可能隐藏了您的真实意图)。

我为它打开了 issue https://github.com/cucumber/cucumber-js/issues/1105 但它被关闭了 :(