×
☰ See All Chapters

Cucumber Scenario

  • A single functionality can have multiple scenarios.  We can include multiple scenarios in a single feature file. 

  • A scenario is the behaviour of the functionality in a particular situation or behaviour of the functionality for the particular input data.  

  • Functionality can behave differently for different circumstances. Those are called scenarios. 

  • Functionality will be complete by considering all the scenarios. 

  • When Cucumber runs a scenario, if the application behaves as described in the scenario, then the scenario will pass; if not, it will fail.  

  • We can add scenarios to feature file when we add new functionality. But it is convention to create new feature file to new functionality. Feature file is a group of different scenarios of a single functionality. One feature file for one functionality.  

  • Scenario keyword should be followed by colon ( : ) to separate the scenario description. 

  • Just like a Feature, a Scenario keyword can be followed by a name and description. Normally you’ll probably just use the name, but it’s valid Gherkin to follow the name with a multiline description everything up until the first Given, When, or Then will be slurped up into the description of the scenario. 

  • Each scenario must be able to execute independently of any other scenario. The login session of one scenario cannot be used for other. Each scenario requires their own sessions. You cannot set data in one scenario and expect the data availability in other scenario. 

  • Cucumber provides provision to make scenarios to communicate and sharing the data, but it’s extremely bad practice: you’ll end up with scenarios that fail unexpectedly and are harder to understand. 

  • Example: 

Feature: With draw money feature test

  Scenario: Main flow

    Given Login as a customer

    Then I want to withdraw money from an ATM

    Then I don’t have to go to the bank

  Scenario: Acceptance criteria

    Given there is enough money on my account

    When I make a withdrawal

    Then I get the expected amount of money from the ATM

 

 


All Chapters
Author