3

我有以下小黄瓜场景:

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 工厂。

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

4

2 回答 2

4

您可以为您的电子邮件和密码字段使用类似 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 |
于 2012-01-12T23:48:44.473 回答
0

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

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

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

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

于 2012-01-17T08:47:08.077 回答