如何在 Python 行为步骤定义中表示 "And"
How to represent "And" in Python behave step definition
例如我在功能文件中有以下场景
Scenario: A Scenario
Given a precondition
When step 1
And step 2
Then step 3
在Ruby中,我可以为上述场景编写步骤定义如下:
Given("a precondition") do
end
When("step 1") do
end
And("step 2") do
end
Then("step 3") do
end
我必须使用 Python Behave 来实现它,我对步骤定义中的 And 实现注释感到困惑,我没有在示例中找到 @and 我推荐。
@given("a precondition")
def given_implementation(context)
pass
@when("step 1")
def when_implementation(context)
pass
#which annotation to use for and??
def and_implementation(context)
pass
@then("step 3")
def then_implementation(context):
pass
And
只是继承了上一步的内容。来自docs,
因此,在您的情况下,您希望将步骤实施更改为以下内容:
@given("a precondition")
def given_implementation(context)
pass
@when("step 1")
def when_implementation(context)
pass
@when("step 2") <--------------------- Changed to this!
def and_implementation(context)
pass
@then("step 3")
def then_implementation(context):
pass
输入@step 而不是@when。而且它将是普遍的。这意味着相同的步骤定义可以与其他关键字一起使用,例如 given, when, then
例如我在功能文件中有以下场景
Scenario: A Scenario
Given a precondition
When step 1
And step 2
Then step 3
在Ruby中,我可以为上述场景编写步骤定义如下:
Given("a precondition") do
end
When("step 1") do
end
And("step 2") do
end
Then("step 3") do
end
我必须使用 Python Behave 来实现它,我对步骤定义中的 And 实现注释感到困惑,我没有在示例中找到 @and 我推荐。
@given("a precondition")
def given_implementation(context)
pass
@when("step 1")
def when_implementation(context)
pass
#which annotation to use for and??
def and_implementation(context)
pass
@then("step 3")
def then_implementation(context):
pass
And
只是继承了上一步的内容。来自docs,
因此,在您的情况下,您希望将步骤实施更改为以下内容:
@given("a precondition")
def given_implementation(context)
pass
@when("step 1")
def when_implementation(context)
pass
@when("step 2") <--------------------- Changed to this!
def and_implementation(context)
pass
@then("step 3")
def then_implementation(context):
pass
输入@step 而不是@when。而且它将是普遍的。这意味着相同的步骤定义可以与其他关键字一起使用,例如 given, when, then