Consider a Behave scenario:
When some magic number is generated
Then the number should be greater than 5
So I have a @when function that produces (say) a random number and I need that number to be present in the @then conditional test.
How do I pass the result of one step to another?
You can set data on the context object passed in to the steps. From the documentation:
@given('I request a new widget for an account via SOAP')
def step_impl(context):
client = Client("http://127.0.0.1:8000/soap/")
context.response = client.Allocate(customer_first='Firstname',
customer_last='Lastname', colour='red')
@then('I should receive an OK SOAP response')
def step_impl(context):
eq_(context.response['ok'], 1)
You can also modify the context at various other points in the test run, before and after every step, feature, scenario, tag, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With