- 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 - Feature Files
Behave works with three different file types, as explained earlier. These files are as follows −
Feature files which are created by the Business analyst or any project stakeholder and contains behaviour related use cases.
Step Implementation file for the scenarios defined in the feature file.
Environment Setup files where the pre/post conditions are to be executed prior and post steps, features, scenarios, and so on.
A Feature file should be within a folder called as the features. Also, there should be a sub-directory steps within the features directory.
The following screen will appear on your computer −
Launching Feature file
We can launch the feature file with various command line arguments, as explained below −
If no information is available, all the feature files within the features directory shall be loaded for the execution in Behave.
If the path of the features directory is provided, then it is mandatory to have at least one feature file (with .feature extension) and a sub-directory named steps within the features directory.
Also, if the environment.py is present, it should be within the directory that has the steps directory and not within the steps directory.
If the path to a feature file is provided, then it instructs Behave to search for it. To get the corresponding steps directory for that feature file, the parent directory is searched.
If not found in the current parent directory, then it searches its parents. This shall continue until it reaches the file system root. Also, if the environment.py is present it should be within the directory that has the steps directory and not within the steps directory.
Structure of a Feature File
A Feature consists of Scenarios. They may/may not contain a description, background, and a group of tags.
A structure of a feature file is as follows −
The format of a 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 like 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')
The output obtained after running the feature file is as follows −
The output shows the Feature and Scenario names, along with the test results and duration of the test execution.