Search code examples
javascriptnode.jscucumberplaywright

cucumber stop execution based on Examples parameter


Is it possible to stop running steps after a condition is met? For a web app with multiple pages, I have scenarios that check all pages, and some stop in the middle.

I would like to use the same feature file and not duplicate the scenario outline, currently, the feature looks like this:

Scenario Outline: TC__<tcNr>__<endScenarioPage>

    # dataPrep step
    Given step for data prep <params1> <params2>

    # page_1
    Given step 1 <params1>
    Given step 2 <params2>

    # page_2
    Then step 1 <params3>
    Then step 2 <params4> <endScenarioPage>

    # page_3
    Then step 1 <params5> 
    Then step 2 <params6>

    # page_4
    Then step 1 <params7>
    Then step 2 <params8>

    @set1
    Examples:
        | tcNr    | params1 | params2 | endScenarioPage |
        | "SCN01" | " ..."  | " ..."  | "page2"         |
        | "SCN02" | " ..."  | " ..."  | "page4"         |
        | "SCN03" | " ..."  | " ..."  | "page2"         |

    @set2
    Examples:
        | tcNr    | params1 | params2 | endScenarioPage |
        | "SCN01" | " ..."  | " ..."  | "page2"         |
        | "SCN02" | " ..."  | " ..."  | "page2"         |
        | "SCN03" | " ..."  | " ..."  | "page4"         |

so for scenarios "SCN01" and "SCN03" from @set1 tests should be stopped on page2.


Solution

  • Scenario Outlines are just a complicated way of writing several individual scenarios in one block of feature code. You would make things much simpler and clearer by not using on outline and just writing individual scenarios. Then your problem of stopping would just disappear, as that scenario would just not have that step

    Scenario: 4 page example
      Given x
      Then 1
      And 2
      And 3
      And 4
    
    Scenario: 2 page example
      Given y
      Then 1
      And 2
    

    Its much better to write many simple scenarios (even if they have lots of repitition than one complex scenario outline (like you have in your question).