Hello,
I am faced with a situation where session values are to be shared across two exec blocks and my limited knowledge about Gatling is a road block.
The following is the use case for a eshop to stress test the number of shopping baskets that can be handled by the backend before giving up.
-
A shopping basket is associated with a eshop session which is identified by a unique id. - eSessId - A POST request created independently
POST call: http:///api/session/create RETURNS a json with eSessId
-
A basket can hold one or several shopping objects and is associated with an eSessId - Also a POST request with the shopping objects as a json array in the body
POST call: http:///api/cart/?sid=
Body: [{“itemId”:“Item1”, “qty”:“1”},{“itemId”:“Item2”, “qty”:“10”}]
ItemIds are stored in a static OS file.
The above has been implemented as in the code below into an object and is called in a scenario and simulated.
It is expected that the server session id created by the “//First Http call to create eSessId” to be shared to the “//Second Http Call comibining Items and eSessId” section.
But it does not seem to happen.
Kindly enlighten with whats happening and any alternate approach.
Error returned is shown in the next code section
`
Anybody … please comment…
Any response would be highly appreciated.
Mvh
Srinivas
You are not setting the query parameter here, you need to retrieve it from the session (session.set, session.get).
`
.queryParam("sid",sessionId)
`
Also, when posting the code, try to keep it as brief as possible (no comments, debug statements etc). It hurts readability.
Hello Eugene,
Thank you for the response.
Could you please elaborate on that, as that is one of the place of confusion.
How to access a session variable that is set in a different session into the http exec block.
My understanding is that a session succeeds an http exec block.
The gatling session parameter can be set in the session block of the First Http call.
How can it be accessed in the .queryParam() using session.get ?
That is why I have used the ‘var sessionid’ to set in the session block of First Http call and tried to retrieve it in the Second Http Call.
But could not.
Refer the toned down code below.
var sessionId=""
var bodyString="""[{"itemid":"""" + "Item1" + """","qty":"1"}]"""
val getSessionId =
//First Http call Block
exec( HttpRequestBuilder.toActionBuilder(http("GeteSessId")
.post("/session/create")
.check(status.is(200))
.check(jsonPath("$..*").find.saveAs("fullSIdJson"))
.asJSON)
)
.pause(1)
.exec(session => {
val sessJsonParsed = parse(session("fullSIdJson").as[String])
Try storing the variable inside the session, something like this
`
.exec(session => {
val sessJsonParsed = parse(session("fullSIdJson").as[String])