Conditional Saving

Gatling version: 3.14.9.5
Gatling flavor: java kotlin scala javascript typescript
Gatling build tool: maven gradle sbt bundle npm

Hello!

I’d like to save a value only when I’m at a specific location. This doesn’t work:

http("Test")
    .get("https://example.org")
    .check(
        currentLocation().saveAs("current_location"),
        // 1st problem: can't have `doIf` here
        doIf(session -> session.getString("current_location").equals("..."))
            .then(css("#id", "attribute").saveAs("value")), // <- 2nd problem: required: Executable, actual: Final
    )

How would I do that?

Hello,

Have you tried Gatling checks scripting reference ?

Hi, Stéphane,

It looks like this with checkIf:

http("Test")
    .get("https://example.org")
    .check(currentLocation().saveAs("current_location"))
    .checkIf(session -> session.getString("current_location").equals("..."))
    .then(css("#id", "attribute").saveAs("value"))

My question wasn’t complete, my apologies. My brain was already steaming.
Not only do I want to save something, I also want to send an extra HTTP request in this case.

  1. Send request A. There can be response 1 or 2.
    • If it’s response 1, save some stuff and send request B. Request B will give me response 2.
  2. Send request C with data from response 2. Response 2 will either come from request A or B.

How to model the sometimes optional request B?

With a doIf as the next element of the chain.

Hi,

Save the current position in a.check(), and then use doIf outside to get:

exec(
  http(“Test”)
    .get("https://example.org")
    .check(currentLocation().saveAs("current_location")),
  doIfEquals("#{current_location}", "…").then(
    http("Conditional Check")
      .get("https://example.org")
      .check(css("#id", "attribute").saveAs("value"))
  )
)

If you want to control flow, don’t mix capture and doIf in the same check.

Doing it like that, I would lose response 2 from request A, wouldn’t I? Do I have to duplicate the checks for both scenarios?