- 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 - Steps in a Step
We can substitute multiple steps in a Scenario with one macro step. This helps us not to repeat the same code in the step definition file. A BDD framework has the capabipty to invoke multiple steps from the step definition.
Feature File with Similar Steps
The feature file with the similar steps is as follows −
Feature − Payment Module Scenario − Verify message after payment Given User is on payment screen When User enters payment details And User completes payment Then User should get success message Scenario − Verify new users can process payment Given User keys in payment info and submits Then success message should get displayed
In the feature file, we have two Scenario with similar steps. In Behave, we can execute more than one step in a single step. This can be done with the help of context.execute_steps method in the step implementation file.
Corresponding Step Implementation File
The corresponding step implementation file for the above mentioned feature file is as follows −
from behave import * @given( User is on payment screen ) def is_on_payment_screen(context): print( User is on payment screen ) @when( User enters payment details ) def enters_payment_details(context): print( When User enters payment details ) @when( User completes payment ) def completes_payment(context): print( When User completes payment ) @then( User should get success message ) def get_success_message(context): print( Then User should get success message ) @given( User keys in payment info and submits ) def payment_info_and_submits(context): #passing steps within steps with context.execute_steps context.execute_steps(u""" Given User is on payment screen When User enters payment details And User completes payment """) @then( success message should get displayed ) def success_message(context): print( Then success message should get displayed )
Output
The output obtained after running the feature file is given below and the command used is behave --no-capture -f plain.
The continued output is as follows −
The output shows that the new users of Scenario Verify can process the payment by having the steps executed from the Scenario Verify new users can process payment.
Advertisements