Skip to main content

Cucumber Scenario

The Scenario is one of the core Gherkin Structures, which is an executable specification of the system in Cucumber. A feature file can have one or more scenarios, and every Scenario consists of one or more steps. Every Scenario starts with the keyword Scenario (or its localized keyword) followed by an optional scenario title. The keyword Scenario is a synonym of the keyword Example.

Steps in a Scenario are executed one at a time in the sequence we have written them in, and each Step has a corresponding Step Definition associated with it.

You will further read about Scenario Outline in the latter course, which is similar to scenario structure; the only difference is the provision of multiple inputs.

Cucumber Scenario Example

#Sample Feature Definition Template

@search
Feature: Title of your feature

  #This is sample scenario
  @smoke
  Scenario: Title of your scenario
    Given I an on the homepage
    When I click on Login Page
    Then i should see Login page

In Scenario, You can have as many steps as you like, but 3-5 Steps per Scenario are recommended. Too many Steps will cause the Scenario to lose its expressive power as a specification and documentation. 

We need to specify the pre-conditions, user actions and expected output when defining business requirements. These can be easily represented using given, when and then.

  • Given: Pre-conditions are mentioned in the Given keyword.
  • When: User actions are described in When.
  • Then: It is used for expected output.

Apart from the above three, we also use And and But keywords in Scenario, which we will discuss later.

Video Tutorial: Scenario in Cucumber

Submitted by tgoswami on August 30, 2020

Tarun has 11+ years of experience in Quality Assurance in different domains like Banking, E-commerce, Health and Education.

About

At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.