Book Image

Cucumber Cookbook

By : Shankar Garg
Book Image

Cucumber Cookbook

By: Shankar Garg

Overview of this book

Table of Contents (13 chapters)
Cucumber Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating Scenarios with different Steps


When we specify a business requirement, we need to specify the pre-conditions, user actions, and expected output. Let's first understand what each of these mean:

  • Pre-condition: This sets the Application Under Test (AUT) in a state where the test case can be executed, or establishing the application context.

  • User action: This refers to the action that a user performs that is in line with the Scenario objective.

  • Expected output: This refers to the application's response after the user action.

So let's have this specification written in Cucumber in this recipe.

How to do it…

In this recipe, we are going to update the Feature file we created in the previous recipe by using the keywords Given, When and Then

Feature: login Page
  In order to test login page
  As a Registered user
  I want to specify the login conditions

  Scenario: checking pre-condition, action and results
    Given user is on Application landing page
    When user clicks Sign in button
    Then user is on login screen

How it works…

A Cucumber Scenario consists of Steps identified with keywords such as Given, When, Then, And, But, and so on. These have been defined as follows:

  • Given: Preconditions are mentioned in the Given keyword. The Steps of the Given keyword put the system in to a known state, which is necessary for the user action. Avoid talking about user interaction in Given Steps.

  • When: The purpose of the When Steps is to describe the user action.

  • Then: The purpose of Then Steps is to observe the expected output. The observations should be related to the business value/benefit of your Feature description.