Behave – Scenario Outlines

Behave - Scenario Outlines

In this chapter, we will discuss Behave Scenario Outlines. A Scenario Outline is accompanied by an Examples table. A Scenario Outline can have multiple Examples tables.

The tests get executed once for every row found (after the header row) within the Examples table. <>. These names should match with the Examples table header.

Behave Scenario Outlines it helps to reduce the lines of code (eliminates repeating steps) and orders our tests.

Feature File

The feature file for the scenario outline is as follows −

Feature − User information
Scenario Outline: Check login functionality
   Given user enters "<name>" and "<password>"
   Then user should be logged in
   Examples: Credentials
      | name   | password |
      | user1  | pwd1     |
      | user2  | pwd2     |

Please Note: We have kept the name and password parameters enclosed in “<>”. These parameters are column headers provided below the Examples section. In the step implementation, we shall pass the parameters enclosed in “{}”.

Also, these parameters need to be passed as arguments to the implementation method.

Corresponding Step Implementation File

The corresponding step implementation file is as follows −

from behave import *
@given('user enters "{name}" and "{password}"')
def step_implpy(context, name, password):
      print("Username for login: {}".format(name))
         print("Password for login: {}".format(password))
@then('user should be logged in')
def step_implpy(context):
      pass

Output

The output is–no-capture -f plain.

Behave - Scenario Outlines

Next Topic – Click Here

This Post Has One Comment

Leave a Reply