- Behave - Discussion
- Behave - Useful Resources
- Behave - Quick Guide
- Behave - Debugging
- Behave - Hooks
- Behave - Reports
- Behave - Retry Mechanism
- Behave - Exclude Tests
- Behave - Runner Script
- Behave - Step Parameters
- Behave - Step Functions
- Behave - Multi-Methods
- Behave - Optional Part
- Behave - Regular Expressions
- Behave - Step Matchers
- Behave - Enumeration
- Behave - Tags
- Behave - Data Types
- Behave - Background
- Behave - Steps in a Step
- Behave - Setup Table
- Behave - Multiline Text
- Behave - Scenario Outlines
- Behave - Step Parameters
- Behave - Supported Languages
- Behave - First Steps
- Behave - Step Implementations
- Behave - Feature Files
- Behave - Gherkin Keywords
- Behave - Feature Testing Setup
- Behave - Configuration Files
- Behave - Command Line
- Behave - Installation
- Behave - Introduction
- Behave - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Behave - Scenario Outpnes
A Scenario Outpne is used if we have a group of similar criteria and the results are to be passed in a Scenario. A Scenario Outpne is accompanied with an Examples table. A Scenario Outpne can have multiple Examples tables.
The tests get executed once for every row found (after the header row) within the Examples table. The values to be tested are represented by their names enclosed in brackets<>. These names should match with the Examples table header.
It helps to reduce the pnes of code (epminates repeating steps) and orders our tests.
Feature File
The feature file for scenario outpne is as follows −
Feature − User information Scenario Outpne: Check login functionapty 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 obtained after running the feature file and the command used is behave --no-capture -f plain.
The output shows Username for login: user1, Password for login: pwd1 and Username for login: user2, Password for login: pwd2 printed. Here, the two data sets were passed from the Examples.
Advertisements