cucumber-jvmcucumber-javascenarios

Writing Cucumber feature file with passing unique data every time test runs


I want to write a feature file that will pass unique data everytime I run my test.

Feature : - Create Facebook account

Scenario Outline: Create new account
    Given I go to facebook.com
    And I enter "First_Name>Last_name>DOB>Password>ConfirmPassword>Email>ConfirmEmail>"
    When I click on Create account
    Then I should get welcome to facebook message

Examples:
    | First_Name | Last_name | DOB        | Password | ConfirmPassword | Email        | ConfirmEmail |
    | Gary       | English   | 11/01/1989 | test123  | test123         | gar@mail.com | gar@mail.com |
    | Barry      | Smith     | 01/11/1982 | test123  | test123         | bar@mail.com | bar@mail.com |

My question is: When I run above scenario there will be 2 Facebook accounts created. When I commit my code and test are run every morning, they will fail unless I change email every-time to make them unique. As any system will check if email address provided already exists or not.

How do I tackle this issue where I don't have to change my Create account feature file data every time.

I hope someone of us should have come across such issue.

Note: I could not open and close <> as text was not visible between those brackets, hence I have kept just 1 bracket


Solution

  • Then don't put it in the feature file. Build a randomizer into the steps method. You should also change the feature file to reflect this.

    And I enter "<First_Name>, <Last_name>, <DOB>, <Password>, <ConfirmPassword>, <Email>, <ConfirmEmail>"
    And uses a random email
    

    Or if you'd rather not build a separate condition, then use a keyword to signal that the value should be randomized (my preferred method):

    |Barry|Smith|01/11/1982|test123|test123|[random]|[random]|
    

    So when passed to the registration method, if the value doesn't validate as a legitimate email address (you are doing validation, right?), check for the [random] keyword. If it is there, then build a random valid email.