Search code examples
rubycucumberbddscenarios

How to write Scenario Outlines with dinamic values ​?


enter image description herefor example:

Scenario Outline:
Given the user is logged into Home Operations
When searching for "<status>"
Then the "<result>" and "<total>" are presented

Examples:
| status  |
|approved |
|created  |
|rejected |
|confirmed|

The result and total are dinamic values. How can I fix this, Please?

***Result*** is the total by status type.
***Total*** is the sum of the statuses.

Solution

  • When you say dynamic value, I presume you are getting that during run time or in other words you wouldn't know the values until you run the BDD. If that's the case, you need to reconsider how you write your BDDs. For every value there should be an agreed outcome. For an example, if the status is approved then for the result and total you should have a value that is defined/agreed upfront.

    For an example, your above BDD could be rewritten as

    Scenario Outline: 
    Given the user is logged into Home Operations 
    When searching for "<status>" 
    Then the "<result>" and "<total>" are presented
    
    Examples:
    | status  | result  |total|
    |approved | success | $20 |
    |created  | pending | $20 |
    |rejected | failed  | $0  |
    |confirmed| success | $20 |
    

    You shouldn't be expecting dynamic values in your test. Your test data should be set up in such a way that you always expect an expected outcome.