Search code examples
robotframeworkgherkin

robot framework - BDD dependency between Given When Then


I recently started working with robot framework for api test development. Gherkin is completely new to me.

How to manage the dependency between the Given and When and Then? For ex: If I say that

Given create account is successful ( which may have the ability to return account no)
When I update my address (this keyword needs the account no set by Given)
Then account should be updated. 

Now for When to work successfully, it should know account id or transaction id or something similar which Given has created. How will Given pass data to When and so on.

How data persists between these keywords? I do not see any examples or BDD is not meant for such kind of examples? Please refer me related links if any.


Solution

  • Your keywords can store data in test variables using set test variable. Test variables are visible to all keywords run during a test.

    See Using Set Test/Suite/Global Variable keywords in the robot framework user guide for more information.

    For example,

    *** Keywords ***
    create account is successful
        ${account number}=  Create the account  
        set test variable  ${account number}