
- Behave Tutorial
- Behave - Home
- Behave - Introduction
- Behave - Installation
- Behave - Command Line
- Behave - Configuration Files
- Behave - Feature Testing Setup
- Behave - Gherkin Keywords
- Behave - Feature Files
- Behave - Step Implementations
- Behave - First Steps
- Behave - Supported Languages
- Behave - Step Parameters
- Behave - Scenario Outlines
- Behave - Multiline Text
- Behave - Setup Table
- Behave - Steps in a Step
- Behave - Background
- Behave - Data Types
- Behave - Tags
- Behave - Enumeration
- Behave - Step Matchers
- Behave - Regular Expressions
- Behave - Optional Part
- Behave - Multi-Methods
- Behave - Step Functions
- Behave - Step Parameters
- Behave - Runner Script
- Behave - Exclude Tests
- Behave - Retry Mechanism
- Behave - Reports
- Behave - Hooks
- Behave - Debugging
- Behave Useful Resources
- Behave - Quick Guide
- Behave - Useful Resources
- Behave - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 like 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 earlier 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 earlier 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 −
