HTTP checks - Saving

34 views
Skip to first unread message

Thomas Polaske

unread,
Aug 26, 2021, 10:51:33 AM8/26/21
to Gatling User Group
I am iterating over the same post statement and would like to save each response somehow in a list.  Is this possible? 

From the reference it only looks like you can save this as a string?  And it looks like if I try to do this multiple times it does not save anything?
https://gatling.io/docs/gatling/reference/current/http/check/#saving

Thanks!
Tom

Sébastien BREVET

unread,
Aug 26, 2021, 10:58:58 AM8/26/21
to gat...@googlegroups.com

Hi!

it looks like if I try to do this multiple times it does not save anything?

saveAs should save your last result.
Are you sure that your last result is not empty?

would like to save each response somehow in a list

My approach is:

  • to create a session variable (acc) with an empty list
  • save the current result in another variable (tmp)
  • make a step to add the second variable to the first one

Something like:

  .exec(session => session.set("acc", session("acc").as[List[String]] :+ session("tmp").as[String])

(warning: not tested)

I hope that helps!

Cheers!



--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gatling/048db3b8-a292-4750-a264-8adef9d39d66n%40googlegroups.com.


--

Sébastien BREVET

Backend engineer

   
sbr...@gatling.io
gatling.io
   
facebook twitter linkedin 

Thomas Polaske

unread,
Aug 26, 2021, 1:48:12 PM8/26/21
to Gatling User Group

Hmm ya that doesn’t seem to be working.  But I’m not sure I initiated the list correctly?   Is this how you would to create a session variable ( resourceUidList  ) with an empty list (couldn’t find anything in the doc about this)?

.exec(session => session.set("resourceUidList", {}))

If that is correct.. it doesnt seem to work when I try to add to it like so

exec(session => session.set("resourceUidList", session("resourceUidList").as[List[String]] :+ session("resourceUid").as[String]))

 the session var is empty

resourceUidList -> ()

What I would like to do is take this list and iterate each value to a PUT request.

Another way I could do that is I add all the resourceIds to a local array variable (not is session)

Then I can iterate over using repeat

repeat(times, counterName) {

  myChain

}

according to the docs times can be an Int,

so my code looks like this

    .repeat(numberOfRulesets, "counter") {

      TestUtil.putRuleset("${rulesetId}", rulesetFilePath, "${counter}").pause(2)  // This is my PUT request

    }

However it does not seem like this counter is working?  Not sure what I am doing wrong but it seems unable to get that value to index on my array.

please let me know if you see anything incorrect about either option thanks!?

Sébastien BREVET

unread,
Aug 26, 2021, 3:01:02 PM8/26/21
to gat...@googlegroups.com
Curly braces are only empty block in Scala.
Try with Nil or List() to initialize it

Thomas Polaske

unread,
Aug 26, 2021, 3:33:51 PM8/26/21
to Gatling User Group
hmm not sure that is going to work :(.  Not sure what I am missing this should be pretty simple.. I posted another question as a workaround
Reply all
Reply to author
Forward
0 new messages