Hi,
I’m making this post hoping someone who has a bit more experience using Gatling (especially saving a value in the session, and using in a subsequent get request) will be able to help me in the right direction.
I have been working on a scenario where I make an http request, grab the value in the location, and using regex save just the token portion I need:
.get(URL)
.check(currentLocation.exists.saveAs(“LOCATION”))
.check(currentLocationRegex(“token=(.*)&encounter_id”).ofType[(String)].
saveAs(“token”))
Then I have a block of code where I prefix Bearer in front of the token and save as a session value:
.exec(
session =>
session.set(“access_token”, "Bearer " + session.attributes(“token”))
)
For debugging I print out what is in the session:
.exec { session =>
println(session)
session
}
And I can verify that the value is there, saved properly in the session, exactly what I need to use.
Then I have a request where I try to set headers:
.headers(
Map(
“accept” → “application/json, text/plain, /”,
//“authorization” → “${access_token}”
//“authorization” → session.attributes(“access_token”),
//“authorization” → session => session(“access_token”).validate[String],
"authorization → “Bearer 3333333”
“sec-fetch-mode” → “cors”,
“sec-fetch-site” → “same-origin”
)
)
Unfortunately if you examine the commented out lines, nothing I’ve tried to access the saved session value for access token in this map command has worked. If I type in the bearer value (the uncommented line) then it works.
So my only problem is how can I get this saved session value into this .header map?
Any help would be very much appreciated as I’ve been scratching my head for a while.
Thanks,
Mark