Parameter Concept in Behave

Here we are going to pass the values from feature file to step definitions file (.py)

We need to define the parameter value in double or single quotes in the feature file under scenario for terms of (Given, When, Then , And ,But) as shown in the below.

Ex: When Enter "abcd@gmail.com" UserID

In steps definition file we need to catch this parameter value using { } and parameter name as “{parameter_name}” and we need to use same name as a parameter in python methods and finally we can use this parameter name to get the value and perform the action accordingly.

“.format” is a string method that is used to concatenate the parameter value with the string.




@when("Enter {pasw} password")
def methodThree(context,pasw):
   print("L3 - Enter the Password {} in Login Screen".format(pasw))

Parameter Concept

Example : In the below example we have created a feature file along with step definitions. Here we pass the parameter values from feature file to step definitions file.

login_screen.feature

# This is a Feature file

Feature: Fill the Contact Form

    Scenario: User Login credentials

        Given Launch the App and Click on Login Button
        When Enter "abcd@gmail.com" UserID
        When Enter '12345' password
        When click on Login Button
        And Home page opens
        Then Verify Home Screen
        Then Take screenshot


LoginScreen.py

from behave import given, when, then


@given("Launch the App and Click on Login Button")
def methodOne(context):
    print("L1 - Launching the App")


@when("Enter {emailid} UserID")
def methodTwo(context,emailid):
    print("L2 - Enter the UserID in Login Screen {} ".format(emailid))


@when("Enter {pasw} password")
def methodThree(context,pasw):
    print("L3 - Enter the Password {} in Login Screen".format(pasw))


@when("Click on Login Button")
def methodFour(context):
    print("L4 - Clicked on the login Button")


@when("Home page opens")
def methodFour(context):
    print("L5 - Home Page opened")


@then("Verify Home Screen")
def methodFive(context):
    print("L6 - Home Screen Opened")


@then("Take Screenshot")
def methodSix(context):
    print("L7 - ScreenShot taken")