3

I have the following Gherkin scenario:

Scenario: User Login
    Given a user account exists the email "[email protected]" and password "surprise"
    And I am on the login page
    When I fill in the following:
      | email | [email protected] |
      | 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!

2 Answers 2

4

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 |
    | [email protected] | surprise |
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.