Extracting Conditional Response Values

Hi Stéphane,

First, I just wanted to say how much I loved Gatling!

Suppose one needed to save into the session, for later execution branching, values which might not always be present.

For instance, given a JSON response such as:

{success=“true”}

It’s easy to extract and save. But suppose we could also get a response like this:

{success=“false”; error_code=123}

We’d like to branch chains based on the value of error_code. But checking for it directly will give us a KO (if some simulations got success=true), even if this is expected, and we succeed on the branch we take.

I take it the correct approach would be to do something like

def xformMaybeV : Option[V]

check(bodyString.transform(xform)).saveAs(“maybeValue”)

Note, this is for 2.0. Also, gatling works very nicely as a library–I’m sure many people would love to use it for functional testing.

Thanks,

kirstin

Hi,

Thanks for you kind words.

Actually, that’s something you already have, even in Gatling 1, see step named “whatever” in Check API:
https://github.com/excilys/gatling/wiki/Checks#wiki-whatever

(beware that it has been renamed into “dontValidate” in next Gatling 2 milestone.

So:

  • have a check (JsonPath is probably the best solution for your use case) on error_code
  • then, you can branch with a “doIf(_.contains(“error_code”))”
    Cheers,

Stéphane