1

For example i have following scenario in a feature file

Scenario: A Scenario
    Given a precondition
    When step 1
    And step 2
    Then step 3

In Ruby i can write stepdefinition for above scenario as following:

Given("a precondition") do

end

When("step 1") do

end

And("step 2") do

end

Then("step 3") do

end

I have to implement this using Python Behave and i am confused about And implementation annotation in stepdefinition for this, i did not find @and in the examples i referred.

@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
Nafeez Quraishi
  • 5,380
  • 2
  • 27
  • 34

2 Answers2

1

And merely inherits from whatever the previous step was. From the docs,

From website

So in your case, you'd want to change your step implementation to the following:

@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
natn2323
  • 1,983
  • 1
  • 13
  • 30
0

Type @step instead of @when. And it will be universal. It means that the same step definition might be used with other keywords like given, when, then

Den Silver
  • 199
  • 16