- 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 - First Steps
Let us create a basic Behave test.
Feature File - payment.feature
The feature file for the Feature titled Payment Types is as follows −
Feature: Payment Types
Scenario: Verify user has two payment options
Given User is on Payment screen
When User clicks on Payment types
Then User should get Types Cheque and Cash
Corresponding Step Implementation File - stepImpPayment.py
The corresponding step implementation file for the above mentioned feature is as follows −
from behave import *
@given('User is on Payment screen')
def impl_bkpy(context):
print('User is on Payment screen')
@when('User clicks on Payment types')
def impl_bkpy(context):
print('User clicks on Payment types')
@then('User should get Types Cheque and Cash')
def impl_bkpy(context):
print('User should get Types Cheque and Cash')
Project Structure
The project structure for the feature Payment Types is as follows −
Output
The output obtained after running the feature file is as mentioned below and the command used here is behave
(myenv) D:\behave\myenv\pythonProject>behave
The output shows the Feature and Scenario names, along with test results, and duration of test execution.
Python Console output is given below −
USING RUNNER: behave.runner:Runner
Feature: Payment Types # features/payment.feature:1
Then User should get Types Cheque and Cash # features/steps/stepImpPayment.py:8 0.001s
Then User should get Types Cheque and Cash # features/steps/stepImpPayment.py:8
1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped
Took 0min 0.001s
Advertisements