Behave – Step Parameters

Behave - Step Parameters

Behave – Step Parameters. We can pass parameters to steps in Behave. Let us see a feature file containing steps having multiple parameters where the varied values have been set. This is helpful in making the automation implementation easier since the total step definitions are lessened.

Behave – Step Parameters Feature File

Consider an example of a feature file as given below โˆ’

Feature โˆ’ Schedule
   Scenario โˆ’ Verify Day and Night Schedule
   Given I reach office at "day" shift
   And I reach office at "night" shift

The feature file contains almost similar steps as in the Given and in the And steps. The only difference is that in the day and night shift timings. Instead of repeating the implementations for almost similar steps, we can pass parameters to the steps in the step definition file.

Please Note โˆ’ In the step implementation, we shall pass the parameter enclosed in {}.

Corresponding Step Implementation File

The corresponding step implementation file is as follows โˆ’

from behave import *
@given('I reach office at "{time}" shift')
def step_implpy(context, time):
      print("Shift is: {}".format(time))

Output

The output obtained after running the feature file is as follows and the command used is behaving –no-capture -f plainโˆ’

Behave - Step Parameters

The output shows Shift is: day and Shift is: night printed. Here, the parameters day and night are passed from the step.

Next Topic – Click Here

This Post Has One Comment

Leave a Reply