Reputation: 51
Steps I am trying to achieve in my gatling request:
1. Hit a request in a loop.
2. Save the value of 'status' from JSON response into 'respStatus'
3. Set 'respStatus' into a session variable 'workStatus'
4. Recursively check for the value of session variable 'workStatus' and exit when its value is changes from creating to anything else.
Here is my code. This one below stops the execution after 1st iteration of this request , checking the response body shows that the value of 'creating' in JSON response did not change at the point when it stopped. What is wrong with the code or is there any alternate to achieve this?
.doWhile(session => !session(workStatus).as[String].equal("creating"),"index"){
exec(http("Request1")
.get(<URL goes here>)
.header(<Headers in a map>)
.check(jsonPath("$..status").saveAs("respStatus")))
.exec(session => session.set("workStatus","${respStatus}"))
.pause(10)
}.pause(10)
Upvotes: 2
Views: 4398
Reputation: 6623
Several errors:
session => session.set("workStatus","${respStatus}")
As explained in the documentation:
This Expression Language only works on String values being passed to Gatling DSL methods. Such Strings are parsed only once, when the Gatling simulation is being instantiated.
For example queryParam("latitude", session => "${latitude}") wouldn’t work because the parameter is not a String, but a function that returns a String.
Your copy from respStatus
to workStatus
is useless.
The correct syntax line 1 is session("workStatus")
, not session(workStatus)
.
In Scala, you would use ==
, not equals
.
Beware wildcard paths in jsonPath cause a full JSON tree scan. If possible, and performance is a concern, you'd better use an exact path.
JsonPath is a failure in its current state, please read this post. If possible, you should switch to JMESPath.
You need headers
, not header
to pass a Map.
.doWhile(session => !session("workStatus").as[String].equal("creating"),"index"){
exec(http("Request1")
.get(<URL goes here>)
.headers(<Headers in a map>)
.check(jsonPath("$..status").saveAs("workStatus")))
.pause(10)
}.pause(10)
Upvotes: 5