【问题标题】:Cucumber - How to remove data duplication from this Gherkin scenario?Cucumber - 如何从这个 Gherkin 场景中删除数据重复?
【发布时间】:2012-01-17 19:18:57
【问题描述】:

我有以下 Gherkin 场景:

Scenario: User Login
    Given a user account exists the email "james.smith@somesite.com" and password "surprise"
    And I am on the login page
    When I fill in the following:
      | email | james.smith@somesite.com |
      | password | surprise |
    And I press "Submit"
    Then....

第二行将电子邮件地址和密码传递给步骤定义,该步骤定义又将这些详细信息传递给 FactoryGirl 工厂。

基本上,我不确定如何从这种情况下删除这种重复的数据,我考虑过使用表格,但看不出这有什么帮助,有人知道如何做到这一点吗?提前致谢!

【问题讨论】:

    标签: ruby cucumber integration gherkin


    【解决方案1】:

    您可以在电子邮件和密码字段中使用类似 FIT 的表格,就像他们在 https://github.com/cucumber/cucumber/blob/master/examples/i18n/en/features/addition.feature 的示例中使用的那样

    Scenario Outline: User Login
        Given my account exists with email <email> and password <password>
        And I am on the login page
        When I fill the email <email>
        And I fill the password <password>
        And I press "Submit"
        Then ...
    
    Examples:
        | email        | password |
        | john@doe.com | surprise |
    

    【讨论】:

      【解决方案2】:

      我们使用的模式是抽象多个场景中常见的细节......

      Given my user exists
      And I am on the login page
      When I login with my credentials
      Then I should .... 
      

      然后我们有一个带有默认值的 yaml 文件,例如有效的用户名、有效的密码、无效的密码……我们的步骤调用了这个文件。

      如果您想尝试大量示例,则另一个答案会更好,我认为我们的方法适用于您想要经常登录的地方,但并不总是在每个场景中都指定“无聊”的东西。

      【讨论】:

        猜你喜欢
        • 2021-04-10
        • 1970-01-01
        • 2011-07-04
        • 1970-01-01
        • 1970-01-01
        • 2015-04-28
        • 2023-03-12
        • 1970-01-01
        • 2020-06-16
        相关资源
        最近更新 更多