Reputation: 2000
I am new to Python and Behave. I am trying to setup a POC for my automation project. I followed the tutorials from the behave document, but when i run behave, it throws steps are not detectable. What am i missing?
my folder structure looks like this.
/features/testone.feature
/features/steps/testone_steps.py
feature file
Feature: Running sample feature
@smoke @regression
Scenario: Login to github and verify it works in testone feature of scenario one
Given Launch GITHUB app with "[email protected]" and "githubtest"
step file
from behave import given, when, then, step
@given(u'Launch GITHUB app with "{text}" and "{text}"')
def step_impl(context, user, password):
print(f"This is the given step with {user} and {password}")
output
λ behave
Feature: Running sample feature # features/testone.feature:1
@smoke @regression
Scenario: Login to github and verify it works in testone feature of scenario one # features/testone.feature:4
Given Launch GITHUB app with "[email protected]" and "githubtest" # None
Failing scenarios:
features/testone.feature:4 Login to github and verify it works in testone feature of scenario one
0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 0 failed, 0 skipped, 1 undefined
Took 0m0.000s
You can implement step definitions for undefined steps with these snippets:
@given(u'Launch GITHUB app with "[email protected]" and "githubtest"')
def step_impl(context):
raise NotImplementedError(u'STEP: Given Launch GITHUB app with "[email protected]" and "githubtest"')
i noticed in my vscode editer , in the steps file, the pylint shows this message.
[pylint] E0611:No name 'given' in module 'behave'
[pylint] E0611:No name 'when' in module 'behave'
[pylint] E0611:No name 'then' in module 'behave'
[pylint] E0611:No name 'step' in module 'behave'
Upvotes: 1
Views: 10557
Reputation: 2061
Your issue is that you're using the incorrect format in your step file. Try this:
from behave import given, when, then, step
@given(u'Launch GITHUB app with "{user}" and "{password}"')
def step_impl(context, user, password):
print("This is the given step with {user} and {password}".format(user, password))
Notice that the parameter defined in the @given
statement matches the parameter passed in the step_impl()
.
Namely, if in the @given
, you have
@given(u'Launch GITHUB app with "
{user}" and "
{password}"')
then in your step implementation, you should have
def step_impl(context,
user,
password)
Without this match, and in your current code, you'll receive the NotImplementedError
because behave is looking for a step implementation with context
and text
as parameters in your step file, i.e. def step_impl(context, text)
.
Upvotes: 1