小黄瓜桌 - 删除重复

时间:2018-06-11 06:56:13

标签: cucumber cucumber-jvm gherkin cucumberjs cucumber-java

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

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

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

请帮助我......

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

3 个答案:

答案 0 :(得分:2)

简而言之,没有。没有办法将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可以删除重复设置步骤(假设它们在功能中的所有方案中都是相同的),并且如果您按照尝试的方式对每个方案大纲进行分组实现,你应该有更多的可读性,并且明确表达了测试的意图。

答案 1 :(得分:0)

我无法给出比@ kyle-fairns更好的答案。

但是为了完整性,因为你的场景可能过于简单(可能隐藏了你的真实意图)。

答案 2 :(得分:0)

我为它https://github.com/cucumber/cucumber-js/issues/1105开了一个问题,但是它已经关闭了:(