# Multiple saveAs on ws.sendText

**URL:** <https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467>\
**Category:** Gatling (Open-Source)\
**Created:** [August 17, 2015, 2:18pm UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467 "2015-08-17T14:18:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Niklas\_Modin](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Niklas\_Modin](https://community.gatling.io/u/Niklas_Modin)\
**Post date:** [August 17, 2015, 2:18pm UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467/1 "2015-08-17T14:18:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [August 19, 2015, 2:59am UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467/2 "2015-08-19T02:59:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Niklas\_Modin](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Niklas\_Modin](https://community.gatling.io/u/Niklas_Modin)\
**Post date:** [August 19, 2015, 9:49am UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467/3 "2015-08-19T09:49:10Z")

</div>

Hi,

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

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

Here is an example response:

---

<div class="post-metadata">

**Author:** ![Niklas\_Modin](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Niklas\_Modin](https://community.gatling.io/u/Niklas_Modin)\
**Post date:** [August 19, 2015, 10:56am UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467/4 "2015-08-19T10:56:35Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Niklas\_Modin](https://avatars.discourse-cdn.com/v4/letter/n/919ad9/32.png) [@Niklas\_Modin](https://community.gatling.io/u/Niklas_Modin)\
**Post date:** [August 19, 2015, 2:30pm UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467/5 "2015-08-19T14:30:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![David\_Leonhartsberge](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@David\_Leonhartsberge](https://community.gatling.io/u/David_Leonhartsberge)\
**Post date:** [August 20, 2016, 5:18pm UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467/6 "2016-08-20T17:18:52Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![slandelle](https://dub1.discourse-cdn.com/flex013/user_avatar/community.gatling.io/slandelle/32/4_2.png) [@slandelle](https://community.gatling.io/u/slandelle)\
**Post date:** [August 20, 2016, 5:24pm UTC](https://community.gatling.io/t/multiple-saveas-on-ws-sendtext/2467/7 "2016-08-20T17:24:59Z")

</div>

We’ll bring a new WebSocket API in Gatling 3.  
Progress and discussion happens here: [https://github.com/gatling/gatling/issues/3071](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,
