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

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

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.

Multiline Text

The output shows the multiline text printed.

Advertisements