- 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 Implementations
The steps of a Scenario in the feature file in Behave should have implementation logic written in Python. This is known as the implementation/step definition file (.py extension) and should be present within the steps directory.
All the necessary imports are present in this file. The steps directory should be a part of the features directory.
The following screen will appear on your computer −
![Step Implementations](/behave/images/step_implementations.jpg)
The step definition file contains Python functions which define the steps in the feature file. At the start of the Python functions, it is mandatory to have decorators which begins with @given, @when, and so on. These decorators compare and match with the Given, Then, When, and other steps in the feature file.
Feature File
The feature file is as follows −
Feature − Verify book name added in Library Scenario − Verify Book name Given Book details Then Verify book name
Corresponding Step Implementation File
The corresponding step implementation file looks pke the one mentioned below −
from behave import * @given( Book details ) def impl_bk(context): print( Book details entered ) @then( Verify book name ) def impl_bk(context): print( Verify book name )
Output
The output obtained after running the feature file is as follows −
![Corresponding Step Implementation File](/behave/images/corresponding_step_implementation_file.jpg)
The output shows the Feature and Scenario names, along with test results, and duration of test execution.
Advertisements