Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is data from one Behave step passed to a later step?

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?

like image 911
Tony Ennis Avatar asked Apr 13 '15 21:04

Tony Ennis


1 Answers

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.

like image 171
Peter Wood Avatar answered Sep 28 '22 01:09

Peter Wood