I have the following Gherkin scenario:

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....

The second line passes the email address & password to a step definition which in turn passess these details to a FactoryGirl factory.

Basically, I am not sure how to remove this duplication of data from this scenario, I thought about using tables but cannot see how this would help, does anyone have any ideas about how to do this? Thanks in advance!

有帮助吗?

解决方案

You can use a FIT-like table for your email and password fields, like they use in the example at 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 |

其他提示

The pattern we use is to abstract details That are common across several scenarios...

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

We then have a yaml file with default values like valid username, valid password, invalid password... Our steps call into this file.

The other answer is better if you want to try lots of examples, I think ours works where you want to login often, but not always specify "boring" stuff in each and every scenario.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top