Complete first behave step definition
Continue from the previous page where we wrote the behave scenario
1. Right Click on the steps folder and create new – python files (Alternately, you can also just select File and create “first_behave.py”)
2. If you imported the python_behave_template, the file “first_behave.py” is already present, so you don’t have to do anything here.
3. Copy paste the below code in the file “first_behave.py”
from behave import *
@given("I have two integers a and b")
context.a = 1
context.b = 2
@when("I add the numbers")
context.sum = int(context.a) + int(context.b)
@then("I print the addition result")
print("Sum of", context.a, "and", context.b, "is:",context.sum)
4. Now right-click on feature in “first_behave.feature” and click “Run….feature file”.
You should notice that the feature will run successfully. A browser will pop up and close, which is fine. The output is as below
5. If you would like to run it from command line , do the following from the root of the project i.e. from “python_behave_template” directory. Running from command line will help us align with “Continuous Test Automation” in the future (also with continuous integration)
Summary: As you can see behave aligns very much with the Cucumber style of ATDD and so far, it looks exactly like cucumber on ruby OR cucumber-jvm on Java side. Good to go right !
Next we will write our first selenium based behave scenario