Learn about Scenarios in part three of our How-To-Guide on applying Cucumber to lead your agile testing team down the path to automation.
Blog three of a series.
In the previous blog Understanding Cucumber Features, we learned where our BDD Acceptance Criteria test scripts need to be placed in the Cucumber automation framework.
But you can’t just copy and paste the script(s) into the .feature file and run them. You need to tell Cucumber that they are scripts. You can accomplish this by using one of three keywords: Scenario, Scenario Outline, or Background.
Scenario Outlines and Backgrounds will be covered in future blogs. Here, we will discuss Scenarios.
Cucumber Scenarios in Agile Testing Words
The Cucumber Book describes each Scenario as “…a single concrete example of how the system should behave in a particular situation. If you add together the behavior defined by all of the scenarios, that’s the expected behavior of the feature itself.”
In agile testing words, each Scenario is a test case. As defined by Software Testing Fundamentals define a test case as “..a set of conditions or variables under which a tester will determine whether a system under test satisfies requirements or works correctly.”
The Acceptance Criteria test scripts are your initial “happy path” scripts. These are the scripts where everything goes right: the correct set-up (Given block), the correct actions (When block) lead to the correct expected results (Then block).
To let Cucumber know a script is a Scenario you need to use the keyword Scenario. The format is:
For the title, you want to make sure it is descriptive enough so you, and future testers, know what is being tested in the Scenario. But try to keep it concise.
A little utilized fact about Scenarios: like the .feature file they are part of, each Scenario has some white space where you can put text. Any lines after the title line, but before the first script line, is white space.
This is a good spot to call out any details or script specific notes not readily apparent in the script. If you wish to include some description, the Scenario format becomes:
We have created a title line, added some notes and are now ready to add our Acceptance Criteria test script. As the formats above show, the scripts go after the title line.
Scenarios, or Test Cases as they are commonly referred to, are what drives the Cucumber test automation framework. With a fully-written Scenario in place, you are now ready to begin automating.