Hi
Using Gatling 2.2.0. How can we save jsonpath result as an array into a Websocket session object?
Here is the json string:
{
“jsonrpc”: “2.0”,
“id”: 6,
“delta”: true,
“result”: {
“qLayout”: [
{
“op”: “add”,
“path”: “/”,
“value”: {
“qInfo”: {
“qId”: “MU2”,
“qType”: “sheet”
},
“qSelectionInfo”: {},
“qAppObjectList”: {
“qItems”: [
{
“qInfo”: {
“qId”: “b93a1db4-65fe-4984-a6ea-3eb26215eddc”,
“qType”: “sheet”
},
“qMeta”: {
“title”: “Subject Information”,
“description”: “Subject information.”,
“privileges”: [
“read”
],
“modifiedDate”: “2016-05-06T11:02:26.367Z”,
“published”: true,
“publishTime”: “2016-05-06T11:02:25.007Z”,
“approved”: true,
“owner”: {
“id”: “f9345cd8-60a9-4c17-903b-a6b19fdb5a5a”,
“userId”: “testing”,
“userDirectory”: “TEST”,
“name”: “testing”,
“privileges”: null
},
“qSize”: -1,
“sourceObject”: “”,
“draftObject”: “”
},
“qData”: {
“rank”: -0.75,
“thumbnail”: {
“qStaticContentUrl”: {}
},
“columns”: 24,
“rows”: 12,
“cells”: [
{
“name”: “a79e7d7e-e4f6-4635-8452-eb82088b5307”,
“type”: “table”,
“col”: 0,
“row”: 6,
“colspan”: 24,
“rowspan”: 6
},
{
“name”: “583b009d-6fb4-4b3b-954a-d2c60db257e9”,
“type”: “filterpane”,
“col”: 0,
“row”: 0,
“colspan”: 3,
“rowspan”: 1
},
{
“name”: “56ecda2b-4e81-4cc2-a76e-30a0ed8513f7”,
“type”: “kpi”,
“col”: 12,
“row”: 0,
“colspan”: 4,
“rowspan”: 3
},
{
“name”: “631ce74e-35ec-4655-844a-a7a4c6492691”,
“type”: “kpi”,
“col”: 16,
“row”: 0,
“colspan”: 4,
“rowspan”: 3
},
{
“name”: “454328e9-d5b9-4729-acd1-18cc4adf686c”,
“type”: “kpi”,
“col”: 20,
“row”: 0,
“colspan”: 4,
“rowspan”: 3
},
{
“name”: “mrbjwm”,
“type”: “filterpane”,
“col”: 0,
“row”: 1,
“colspan”: 3,
“rowspan”: 1
},
{
“name”: “WJPD”,
“type”: “text-image”,
“col”: 3,
“row”: 0,
“colspan”: 2,
“rowspan”: 3
},
{
“name”: “FGSjM”,
“type”: “text-image”,
“col”: 5,
“row”: 0,
“colspan”: 7,
“rowspan”: 3
},
{
“name”: “VqTRpZE”,
“type”: “text-image”,
“col”: 0,
“row”: 3,
“colspan”: 5,
“rowspan”: 3
},
{
“name”: “Euzn”,
“type”: “text-image”,
“col”: 5,
“row”: 4,
“colspan”: 19,
“rowspan”: 2
}
],
“title”: “Subject Information”,
“description”: “Subject information.”
}
},
{
“qInfo”: {
“qId”: “e1c301cd-3a60-4c24-9fa8-e7726213a3b9”,
“qType”: “sheet”
},
“qMeta”: {
“title”: “User Information”,
“description”: “User Information.”,
“privileges”: [
“read”
],
“modifiedDate”: “2016-05-06T11:02:26.367Z”,
“published”: true,
“publishTime”: “2016-05-06T11:02:25.007Z”,
“approved”: true,
“owner”: {
“id”: “f9345cd8-60a9-4c17-903b-a6b19fdb5a5a”,
“userId”: “testing”,
“userDirectory”: “TEST”,
“name”: “testing”,
“privileges”: null
},
“qSize”: -1,
“sourceObject”: “”,
“draftObject”: “”
},
“qData”: {
“rank”: 0.625,
“thumbnail”: {
“qStaticContentUrl”: {}
},
“columns”: 24,
“rows”: 12,
“cells”: [
{
“name”: “148ad404-7531-471f-99c7-e31d579e235f”,
“type”: “table”,
“col”: 0,
“row”: 7,
“colspan”: 24,
“rowspan”: 5
},
{
“name”: “1c52b61e-a943-45a3-8a7d-ac7d752931c9”,
“type”: “piechart”,
“col”: 13,
“row”: 0,
“colspan”: 11,
“rowspan”: 6
},
{
“name”: “252df62e-17a7-4240-a73a-3d376167e1c6”,
“type”: “linechart”,
“col”: 0,
“row”: 3,
“colspan”: 13,
“rowspan”: 4
},
{
“name”: “tetPuC”,
“type”: “text-image”,
“col”: 3,
“row”: 0,
“colspan”: 2,
“rowspan”: 3
},
{
“name”: “mBLmRe”,
“type”: “text-image”,
“col”: 5,
“row”: 0,
“colspan”: 8,
“rowspan”: 3
},
{
“name”: “XTyaW”,
“type”: “filterpane”,
“col”: 0,
“row”: 1,
“colspan”: 3,
“rowspan”: 1
},
{
“name”: “RLvpQKT”,
“type”: “filterpane”,
“col”: 0,
“row”: 0,
“colspan”: 3,
“rowspan”: 1
},
{
“name”: “EcaPxyq”,
“type”: “filterpane”,
“col”: 0,
“row”: 2,
“colspan”: 3,
“rowspan”: 1
}
],
“title”: “User Information”,
“description”: “User Information.”
}
}
]
}
}
}
]
}
}
Using http://www.jsonquerytool.com/#/JSONPath $…qItems[1].qData…cells[*].name we get this array:
[
“148ad404-7531-471f-99c7-e31d579e235f”,
“1c52b61e-a943-45a3-8a7d-ac7d752931c9”,
“252df62e-17a7-4240-a73a-3d376167e1c6”,
“tetPuC”,
“mBLmRe”,
“XTyaW”,
“RLvpQKT”,
“EcaPxyq”
]
With this gatling code we are getting only the first value as string:
.exec( ws(“GetLayout 6 WSS”)
.sendText("""{“method”:“GetLayout”,“handle”:3,“params”:[],“delta”:true,“id”:6,“jsonrpc”:“2.0”}""")
.check( wsAwait.within(2).until(1).jsonPath("$…qItems[1].qData…cells[*].name").saveAs(“names”) ) )
.exec(session => {
if (session.contains(“names”)) {
println(“WSS session attribute names=> " + session(“names”).as[String])
}
session
})
.foreach(”${names}", “name”) {
exec( ws(“GetObject 7 WSS”)
.sendText("""{“method”:“GetObject”,“handle”:1,“params”:["${name}"],“id”:count++,“jsonrpc”:“2.0”}""") )
.exec( ws(“Cancel WS”).cancelCheck )
}
Running the gatling code shows this:
WSS session attribute names=> 148ad404-7531-471f-99c7-e31d579e235f
and there is this error in the log file:
2016-05-31 13:22:07,213 ERROR [GatlingSystem-akka.actor.default-dispatcher-7] i.g.c.s.LoopBlock$ [Block.scala:42]
Condition evaluation crashed with message ‘Can’t cast value 148ad404-7531-471f-99c7-e31d579e235f of type class java.lang.String into interface scala.collection.Seq’, exiting loop