# 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 is lessened.

Feature File

Consider an example of 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 the 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 the similar steps, we can pass parameters to the steps in the step definition file.

Please Note − We have kept the day and night parameters in double-quoted text (single-quoted text can also be used) in the feature file. In the step implementation, we shall pass the parameter enclosed in {}.

Also, the parameter is passed as one of the arguments to the implementation method.

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 behave --no-capture -f plain

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