- 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 - Step Functions
Step functions are created in the Python files which exist within the steps directory. Every Python file (having extension as .py) inside that directory gets imported to get the step implementations.
Once the feature files get triggered for execution, the implementation files get loaded. The step functions are associated with the step decorators.
The step implementations must begin with the import, by using the command mentioned below −
from behave import *
This will import multiple decorators described in Behave to help us to locate our step functions. The decorators pke the given, when, then, and so on accepts one string argument.
For example, consider the code given herewith −
@given( user is on admin screen ) def step_impl(context): pass
The above code shall match the Given step of the below feature file, which is as follows −
Feature − Admin Module Scenario − Admin verification Given user is on admin screen
The steps starting with And/But in the feature file are renamed to their earper step keyword.
For example, consider the feature file given below −
Feature − Admin Module Scenario − Admin verification Given user is on admin screen And user is on history screen Then user should be able to see admin name But user should not able to check history
The And step shall be renamed to the Given step and the But step shall be renamed to the earper step keyword. All these are handled internally.
If there are more than one And/But steps consecutively, they would inherit the keyword of non And or But keyword.
The step function having the step decorator shall have a minimum one parameter. The first parameter is known as the context variable. Other parameters come from step parameters (if required).
For example, refer the step function as per the step parameter.
@given( user is on admin screen ) def step_impl(context): pass
Project Structure
The project structure for the feature is as follows −
Advertisements