Search code examples
gherkincucumberjs

Capturing conditions in scenarios


If I have conditions for a successful scenario, I can write it as Given, And, And... Then button is enabled., but how would I write the negative scenario of If either x,y, or z aren't set, the button remains disabled.

Here's an example of the positive scenario:

Scenario: Enable the Add to Favorites button
When the consumer is viewing an item
And the consumer selects an item
And the consumer selects a size
And the consumer selects a quantity
Then the Add to Favorites button becomes enabled

Can (or should) that be accomplished in one scenario? Since all successful "button enable" scenarios require these 3 elements, would I add them to a Before() hook?

Thanks for your time and attention.


Solution

  • All good responses! Thanks for the input. Below is the form I went with:

    Feature: Add item to Favorites List
    
        As a consumer (guest or member) who is shopping on the App, I'd like the ability to favorite items that I maybe interested in.
    
    Rule: Any consumer, guest or member, can favorite an item after selecting pre-requisites (size/quantity/shipping)
    
    Scenario: Favorite an item - member
    Given I have logged in
    And I have searched the product inventory
    When I choose a desired item with specified pre-requisites
    Then the app should allow me to add it to my member favorites list
    
    Scenario: Favorite an item - guest
    Given I have not logged in
    And I have searched the product inventory
    When I choose a desired item with specified pre-requisites
    Then the app should allow me to add it to my guest favorites list