how to use variable from previous step in asLongAs

111 views
Skip to first unread message

letstestthis

unread,
Jun 26, 2015, 2:22:52 PM6/26/15
to gat...@googlegroups.com
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

1.)  .check(jsonPath("$.status").saveAs("status"))

2.)  asLongAs(status == "review", exitASAP = true){
exec(http("get import")
.get("/path/status")
.check(jsonPath("$.status").saveAs("status")))}

I am still quite new to gatling and scala, how do I use the status variable? Also, is the way I am using asLongAs correct?

Thanks

Andrew Krischer

unread,
Jun 26, 2015, 9:27:32 PM6/26/15
to gat...@googlegroups.com
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.

letstestthis

unread,
Jun 28, 2015, 2:08:26 PM6/28/15
to gat...@googlegroups.com
Thank you for this well explained answer!
Reply all
Reply to author
Forward
0 new messages