how to use variable from previous step in asLongAs

Hi 

I have a a variable called status saved in a previous step and would like to use it in the next step which is asLongAs

Hey there!

If you haven’t already, I recommend looking at the Scenario reference doc.

So to answer your questions, when 1) is executed, whatever is at “$.status” in your json response will be mapped to the key “status” in the session. So anywhere that you have access to the session, you will have access to that value (and any other SessionAttributes).

So regarding 2), the docs say that asLongAs’s first argument is a session function that returns a boolean. So it actually takes a function that has session as the input and Boolean as the output. The actual signature is, I believe, (Session) => Boolean. This is good for you, since you want to compare what the json response returned (which you store in the session). So if you replace status == “review” with

session => session(“status”).as[String] == “review”, as long as the value stored in the session map for key “status” is equal to “review”, you will execute the behavior in the code blocks. session => session(“status”).as[String] == “review” is an anonymous function that takes a Session as an input and outputs a Boolean, thus satisfying asLongAs’s contract.

**Note that if this asLongAs call executes and there is no value stored in the session for key “status”, you’ll get some exceptions. If you want to call that block and you know “status” may or may not be defined, use Options instead.

Thank you for this well explained answer!