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−
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
Pingback: Behave - Supported Languages - Adglob Infosystem Pvt Ltd