Search code examples
cucumberscenarios

How to organize a Cucumber feature file when there is a common "Then"?


I have the following two scenarios in my feature file:

@system-A @updating-dob
Scenario: Updating customers dob
  Given an account from system A
  When I save the dob
  Then I should see the dob is updated successfully

@system-B @updating-dob
Scenario: Updating customers dob
  Given an account from system B
  When I save the dob
  Then I should see the dob is updated successfully

As you can see I have two scenarios in the same file but only the Given is different. Is there a way I can combine these two scenarios using Scenario Outline?

BTW, the step definition for

  Given an account from system A
  Given an account from system B

is 10 lines of code.


Solution

  • Yes, you can use a scenario outline:

    @updating-dob
    Scenario Outline: Updating customer's dob
      Given an account from system <system>
      When I save the dob
      Then I should see the dob is updated successfully
    
    Examples:
      | system |
      | A |
      | B |
    

    You can't have @system-A on the example that tests system A and @system-B on the example that tests system B, however.