Step Definition file

Now after creating the feature file we need to define a step definition file for scenarios.

We need to create a package as “steps” and inside it we need to create a python class (.py files) and define all the steps under by creating normal python methods and tag it with feature terms like (Given, When, Then , And ,But) which we define in the feature file.

We need to tag the python methods in steps package class (.py) files with the same name whatever we have defined in the feature file.

Because while executing the feature file behave framework search the the step definition in steps package based on feature terms (Given, When, Then , And ,But).

Step Definition file

Example : Now we need to create step definitions files for previously created login_screen.feature file.

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 UserID")
def methodTwo(context):
    print("L2 - Enter the UserID in Login Screen")


@when("Enter password")
def methodThree(context):
    print("L3 - Enter the Password in Login Screen")


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







ContactForm.py

from behave import given, when, then


@given("Launch the App and Click on ContactForm")
def methodOne(context):
    print("C1 - Launching the App")


@when("Launch the App and Click on ContactForm")
def methodTwo(context):
    print("C2 - Enter the UserID in Login Screen")


@when("Enter Name")
def methodThree(context):
    print("C3 - Enter the Password in Login Screen")


@when("Enter Email")
def methodFour(context):
    print("C4 - Clicked on the login Button")


@when("Enter Mobile Number")
def methodFive(context):
    print("C5 - Home Screen Opened")


@when("we need to click on submit button")
def methodSix(context):
    print("C6 - Clicking on Submit button")


@then("Click on submit")
def methodSix(context):
    print("C7 - Click on the submit button")


@then("Take Screenshot of contact Form")
def methodSix(context):
    print("C8 - ScreenShot taken")