A Variable which can be accessed throughout the program in the same file is known as Global value.
In Behave we can achieve this by using context attribute.
After passing the value as a parameter,Now we need to create a variable along with the term “context” attribute and append the parameter name to it.
context.eid = emailid
Now, The name “context.eid” can be used across the program as required.
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):
context.eid = 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 {}".format(context.eid))
@then("Verify Home Screen")
def methodFive(context):
print("L6 - Home Screen Opened")
@then("Take Screenshot")
def methodSix(context):
print("L7 - ScreenShot taken")