Multiple saveAs on ws.sendText

Hi all,

I looked through the topics for how to save multiple jsonPath values from a web socket response and found a few answers.

  1. Using multiple (see below) checks give me "too many arguments for method check". Maybe vargars for check is gone ?

.sendText( “”"{ “action”:“start” }""")

.check(
wsAwait.within(10).until(1).jsonPath("$.control.session_id").saveAs(“session_id”),
wsAwait.within(10).until(1).jsonPath("$.control.subsession_id").saveAs(“reg_sub_session_id”)
))

  1. Doing .check(…).check(…) etc fails to save anything but the last which I assume after reading forum is due to the immutability ?

Any other solution / tips on how to save multiple jsonPath results from a json response on a web socket ?

Cheers,
Niklas

Hi,

No, setting multiple checks on websockets is not currently supported.

It’s very complex actually. What would the behavior be? Wait until all of them get resolved? Keep going as soon as one gets resolved but fail the other ones? Try to keep on resolving them in the background? Would the answer to this question be generic enough, or is it specific to your use case?

Hi,

No you are absolutely right, the semantics with multiple checks just doesn’t make sense. I think I managed to confuse us both. :slight_smile:

I’m not really looking for multiple checks, rather saving multiple parts of the json response.

Here is an example response:

Also I should let you know that my Scala experience sums up to about 1,5 weeks so please be gentle with assumptions. :slight_smile:

For instance I’m not sure what Right(Vector()) actually means. I assume it’s a vector that I can iterate
over and get to the actual values somehow.

/Niklas

Ok, so this is my solution. I’m guessing there are better ways of doing this, but this is what I came up with

`
val sendConnect = exec(ws(“Send Connect Action”)
.sendText("""
{
“control”: {
“type”: “request”,
“sequence”:“1”,
“version”:“1.0”
},
“header”: {
“action”: “connect”
}
}""")
.check(wsAwait.within(10).until(1).regex(".*").saveAs(“connect_response”))
).exec { session =>

val connectResponse = session(“connect_response”).as[String]
val json = (new ObjectMapper).readValue(connectResponse, classOf[Object])
val initiator = JsonPath.query("$.header.initiator", json).right.map(.toVector)
val session_id = JsonPath.query("$.control.session_id", json).right.map(
.toVector)

val initiatorVal = initiator.right.get.head
val sessionVal = session_id.right.get.head
val newSession = session.set(“initiator”,initiatorVal).set(“session_id”,sessionVal)
newSession
}
`

Feel free to comment as I feel this isn’t the most elegant solution out there. For instance the complete response message is stored
in the session along with the subparts of it.

Niklas

I have the same problem.
I would like to save some other JSON property that I am not checking for.

More concretely:
I want to check if the “requestId” property matches but I want to save the “sessionId” property of the message.

It would be cool if there is a “save” method which gives you access to the complete message which contained the match and not only to the path which is specified via “jsonPath” or “jsonpJsonPath”

We’ll bring a new WebSocket API in Gatling 3.
Progress and discussion happens here: https://github.com/gatling/gatling/issues/3071
What you’re mentioning is what we currently call “matching”.
Note that milestones of the next versions are only available to our support offer subscribers.

Cheers,