Extracting response data without the use of checks

The performance testing app that we are building is configurable to optionally run checks. By the looks of several tutorials it appears that I can only extract data from a response to use in future calls if the code is inside of a checker. These two functionality don’t seem directly related. How can I extract from a response without checks?

in gatling you extract values in the check blocks, but you have the option of making checks .optional if you just want to get a value from the response.

you can also access the entire response in a checkIf block and then use a transform and save to store pretty much anything you like in the session.

you can

Hi James,

could you please share such example of using check/optional/checkIf/transform to save anything we like from the response in the session?

Been trying all day long and there are not many examples on this. I’ve not been successful so far.

Thanks in advance.

Christian

Here’s a couple of examples adapted from my current project…

I make a call which returns a list of ids that I want to submit to a later call, BUT the list might legitimately empty. I want the ids if they exist, but don’t want to fail the step if there aren’t any

`

.exec(http("get ids")
  .post("...")
  .check(
    status.is(200),
    jsonPath("$..id").findAll.optional.saveAs("ids")
  )
)

`

then I can wrap my later step in a doIf block and use the condition ${ids.exists()} to only execute if I got some ids back.

for checkIf and transforms I have the following scenario…

I run tests against snapshots of production data that sometimes have data quality issues. In a scenario similar to the one above I might get a list of ids to submit to a later call, but this call might error due to some of these ids not having mandatory values. In this situation I use checkIf to get the details of the invalid ids so that I can resubmit my call with them removed from the list.

`

exec(http("submit ids")
  .post("...")
  .body(StringBody("""{"ids": ${ids}}""")
  .check(
    checkIf((response: Response, session: Session) => response.body.string.contains("There were missing details for one or more ids")) {
      jsonPath("$.details..error").findAll.transform(
        (errors, session) => {
          session("ids").as[Seq[String]]
            .diff(errors.map(error => "^Missing details for id: ([\\d]+)".r.findFirstMatchIn(error).get.group(1)))}
      ).saveAs("ids")
    }
)

`

so if I get an error message in the response I can find the individual ids that have issues, remove them from the list of ids in my session and try again (this code is all wrapped in a tryMax block)

Thanks for sharing these powerful snippets, James.

I guess I need to invest more time in learning some Scala and Gatling DSL to reach your level.