- 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 - Multiline Text
A block of text after a step enclosed in """ will be linked with that step. Here, the indentation is parsed. All the whitespaces at the beginning are removed from the text and all the succeeding lines must have at least a minimum whitespace as the starting line.
A text is accessible to the implementation Python code with the .text attribute within the context variable (passed in the step function).
Feature File - user.feature
The feature file for feature titled User information is as follows −
Feature: User information
Scenario: Check login functionality
Given user enters name and password
"""
Tutorialspoint Behave
Topic Multiline Text
"""
Then user should be logged in
Corresponding Step Implementation File - userSteps.py
The corresponding step implementation file for the feature is as follows −
from behave import *
@given('user enters name and password')
def step_impl(context):
#access multiline text with .text attribute
print("Multiline Text: " + context.text)
@then('user should be logged in')
def step_impl(context):
pass
Output
The output obtained after running the feature file is mentioned below and the command used is behave --no-capture -f plain.
(myenv) D:\behave\myenv\pythonProject>behave --no-capture -f plain
USING RUNNER: behave.runner:Runner
Feature: User information
Scenario: Check login functionality
Multiline Text: Tutorialspoint Behave
Topic Multiline Text
Given user enters name and password ... passed in 0.002s
"""
Tutorialspoint Behave
Topic Multiline Text
"""
Then user should be logged in ... passed in 0.000s
1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped
Took 0min 0.002s
The output shows the multiline text printed.
Advertisements