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}`)
);
}