Gatling TS: generate .resources() list dynamically based on session

Gatling version: 3.14.101
Gatling flavor: typescript
Gatling build tool: npm

Hello,

I’m testing a scenario where the browser retrieves multiple image tiles concurrently from a server. I want to replicate this in Gatling by using HttpRequestActionBuilder.resources() to fetch the tiles in parallel.

I know I could record the sequence of tile requests and inject it into .resources(), but that would be very tedious as I have multiple scenarios with various inputs. Instead, I would like to write a function that generates a HttpRequestActionBuilder[] based on session information. The difficulty is that the list length depends on session information.

I know it’s possible to inject session variables using Gatling EL when calling individual DSL methods with string parameters. But in my case I want a function that returns a list whose size depends on session data. Is that possible?

Here’s a simplified example of what I’m trying to do. (Note: getSession() doesn’t exist, it’s just to illustrate the issue.)

import { scenario, Session } from "@gatling.io/core";
import { http } from "@gatling.io/http";

export default scenario("Dynamic resources")
  .feed(dataFeeder)
  .exec(
    http("Main page")
      .get("/page")
      .resources(...myResources())
  );

function myResources() {
  const count = getSession().get<number>("count"); // placeholder
  const items = Array.from({ length: count }, (_, i) => i + 1);
  return items.map(item =>
    http("Tile").get(`/tile/${item}`)
  );
}

That’s not possible. The requests parameters can be dynamic but the list of requests is static.

Thanks for the quick response @slandelle . And there is no other way to generate concurrent requests, right?

The number of requests but be static, not resolved dynamically from the Session.

The only thing you can do is

.resources(
  http("Tile").get("/tile/0"),
  http("Tile").get("/tile/1"),
  http("Tile").get("/tile/2")
)

The values of the parameters passed to http and get can be dynamic, but not the list itself.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.