Hello there.
I have a websocket server which returns a JSON with some data if I subscribe on proper model with proper id.
I have a list of those ids and subscribe in the loop on model with each id.
Server returns JSON on every subscription.
I fetch via jsonPath another ids and save them.
Problem is that in next iteration previously saved ids would be overwritten by new ones.
Lets say:
With first run of the loop I’ll receive 10 “anotherids”
With second - five.
With the last - one.
So “anotherIds” in the end of the loops will contain only one id instead of all that was collected during the loop.
Is there a way to accumulate data in ‘saveAs’ variable with each loop iteration?
Example of code:
val subscription = exec(ws(“subscribe on model”)
.sendText("""[“subscribe_on_model”, {“collection”: “Model”, “id”: 2}]""")
.check(wsAwait.within(20).until(1).jsonPath("$…someIds[*]").findAll.saveAs(“someIds”)))
.foreach("${someIds}", “someId”) {
exec(ws(“subscribe on model2”)
.sendText("""[“subscribe_on_model”, {“collection”: “Model2”, “id”: “${someId}”}]""")
.check(wsAwait.within(20).until(1).jsonPath("$…anotherIds[*]").findAll.saveAs(“anotherIds”)))
}
.foreach("${anotherIds}", “anotherId”) {
exec(ws(“subscribe on model3”)
.sendText("""[“subscribe_on_model”, {“collection”: “Model3”, “id”: “${anotherId}”}]""")
.check(wsAwait.within(20).until(1).jsonPath("$…someAnotherIds[*]").findAll.saveAs(“someAnotherIds”)))
}