我对Python很陌生,行为举止也不错。我正试图为我的自动化项目设置一个POC。我遵循了“行为”文档中的教程,但是当我运行“行为”时,它抛出的步骤是不可检测的。我遗漏了什么?
我的文件夹结构是这样的。
/features/testone.feature
/features/steps/testone_steps.py特征文件
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 "test@test.com" and "githubtest"step文件
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}")输出
λ 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 "test@test.com" 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 "test@test.com" and "githubtest"')
def step_impl(context):
raise NotImplementedError(u'STEP: Given Launch GITHUB app with "test@test.com" and "githubtest"')我在vscode编辑器中注意到,在steps文件中,pylint显示了以下消息。
[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'发布于 2018-06-14 15:05:51
您的问题是在step文件中使用了不正确的格式。试试这个:
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))注意,@given语句中定义的参数与step_impl()中传递的参数匹配。
也就是说,如果在@given中,您有
@given(u'Launch GITHUB app with "{user}" and "{password}"')
那么在您的步骤实现中,您应该
def step_impl(context,user,password)
如果没有此匹配,并且在当前代码中,您将收到NotImplementedError,因为parameters正在寻找一个步骤实现,其中的参数是context和text作为步骤文件中的参数,即def step_impl(context, text)。
https://stackoverflow.com/questions/50844576
复制相似问题