My response body is
["Admin","user","Su"]
At times it will return
["Admin","user"] or ["Admin"]
My next request uses a queryparam
As ?roles=Admin,user,Su
Or ?roles=Admin,user
Based on previous response.
Am trying to save response as bodyString
And then retrieving it from session and removing the doublequotes and square brackets using string replace and storing the value in a var and then using it in next request.
When i print the var it does print the values correctly
Eg: Admin,user,Su
But its giving me empty value for my variable when i use the var in the next request.
Any help why i am getting an empty value.
Hi Snow Man,
Are you sure you return the modified session after storing into your value? (in scala, you should avoid using var keyword)
https://gatling.io/docs/current/session/session_api#setting-attributes
Hence the session is immutable, if you are not returning it once modified, the next request will not be aware of this modified version.
Hi Sebastian,
Thanks for your reply. Yes i am returning.
My test is as below. Pls ignore any typos or case in typing.
Def getRoles()={
Var newRoles=""
exec{session=>
newRoles= session("roles").toString.replaceAll("","")
session.set("newRoles",newRoles)
session
}
.exec(http("getreq")
.get("/summary/${newRoles}")
}
Hi Snow Man,
Actually, you are returning the pristine session.
As said, the session is immutable.
def getRoles()={
exec{ session=>
val newRoles = session(“roles”).toString.replaceAll("","") // <= seem that something is missing in replaceAll arguments here copy pasta issue?
session.set(“newRoles”, newRoles) // set returns the updated session
}
.exec(http(“getreq”)
.get("/summary/${newRoles}")
}
The above code should work better
Thank you for the prompt reply,
I have tried just exactly as you said, however the newRoles attribute in the session now holds all the session information with the modified roles values in "roles" key.
So ${newRoles} is giving me all the session information rather than just the string value we have set.
Am i doing anything wrong.
Thanks in advance.
Please check what is the value of session(“roles”) at the beginning. How do you capture it in the first place?
You would also want to check (with println? but ensure that is not the last instruction when returning something like the session) that each step is doing its job.