Use this file to discover all available pages before exploring further.
A Gatling scenario is a blueprint that describes the sequence of actions a virtual user will perform during a load test. Every step — from sending HTTP requests to pausing between actions, branching on conditions, looping over lists, or gracefully handling errors — is expressed through the scenario DSL. Scenarios are composable: you can extract chains into reusable constants, combine them with loops and conditionals, and ultimately attach them to an injection profile in setUp.
exec is the primary method for attaching actions to a scenario. An action is usually a protocol request (HTTP, WebSocket, JMS, MQTT, etc.), but it can also be a function that reads or modifies the session.
Java
JavaScript / TypeScript
// attached to a scenarioscenario("Scenario") .exec(http("Home").get("https://gatling.io"));// directly created and stored in a referenceChainBuilder chain = exec(http("Home").get("https://gatling.io"));// executed sequentiallyexec( http("Home").get("https://gatling.io"), http("Enterprise").get("https://gatling.io/enterprise"));// chainedexec(http("Home").get("https://gatling.io")) .exec(http("Enterprise").get("https://gatling.io/enterprise"));
// attached to a scenarioscenario("Scenario") .exec(http("Home").get("https://gatling.io"));// directly created and stored in a referenceconst chain = exec(http("Home").get("https://gatling.io"));// executed sequentiallyexec( http("Home").get("https://gatling.io"), http("Enterprise").get("https://gatling.io/enterprise"));// chainedexec(http("Home").get("https://gatling.io")) .exec(http("Enterprise").get("https://gatling.io/enterprise"));
You can pass a function to exec to read or update the Session. This is primarily used for debugging or for programmatic session manipulation.
Functions passed to exec run on Gatling’s shared threads. Never perform long blocking operations (remote calls, file I/O, etc.) inside them — doing so will stall the engine.
Gatling SDK components are definitions, not actions. Creating an HTTP request object inside an exec function has no effect — it must be chained into the scenario, not instantiated inside a function body.
Java
JavaScript / TypeScript
exec(session -> { // for debugging only — sysout is slow under load System.out.println(session); return session;});exec(session -> session.set("foo", "bar"));
Use pause to model the time a user spends reading a page before their next interaction. It supports fixed durations, uniform random ranges, EL strings, and functions.
pace is a special pause type that adjusts its wait time based on how long the previous iteration took, allowing you to target a specific iterations-per-second rate regardless of processing time.
Java
JavaScript / TypeScript
forever().on( pace(5) .exec( // runs every 5 seconds, regardless of inner pause durations pause(1, 4) ));
When using the optional counterName parameter to name a loop counter, treat that session attribute as read-only. Writing to it will break Gatling’s internal loop tracking logic.
repeat
Repeat the loop body a fixed number of times (int, EL string, or function).
foreach
Iterate over every element in a sequence, binding each element to a session key.
during
Loop for a fixed duration; optionally exit early between elements (exitASAP).
asLongAs
Loop while a boolean condition holds; condition evaluated before each iteration.
doWhile
Like asLongAs but the condition is evaluated after each iteration.
asLongAsDuring
Loop while a condition holds AND the duration has not elapsed; condition checked before each iteration.
doWhileDuring
Like asLongAsDuring but the condition is evaluated after each iteration.
forever
Loop indefinitely until an error or an explicit exit action terminates the user.
Java
JavaScript / TypeScript
// repeat N timesrepeat(5).on(http("name").get("/"));repeat("#{times}").on(http("name").get("/"));repeat(5, "counter").on(http("name").get("/?counter=#{counter}"));// foreach over a listforeach(List.of("elt1", "elt2"), "elt").on( http("name").get("/?elt=#{elt}"));// loop for a durationduring(Duration.ofMinutes(10)).on(http("name").get("/"));during(5, "counter", false).on(http("name").get("/?counter=#{counter}"));// loop while condition holds (condition before each iteration)asLongAs("#{condition}").on(http("name").get("/"));asLongAs(session -> session.getBoolean("condition")).on(http("name").get("/"));// loop while condition holds (condition after each iteration)doWhile("#{condition}").on(http("name").get("/"));// loop while condition holds AND duration not elapsedasLongAsDuring("#{condition}", Duration.ofMinutes(5)).on(http("name").get("/"));// same but condition evaluated after each iterationdoWhileDuring("#{condition}", Duration.ofMinutes(5)).on(http("name").get("/"));// loop foreverforever().on(http("name").get("/"));
// repeat N timesrepeat(5).on(http("name").get("/"));repeat("#{times}").on(http("name").get("/"));repeat(5, "counter").on(http("name").get("/?counter=#{counter}"));// foreach over a listforeach(["elt1", "elt2"], "elt").on( http("name").get("/?elt=#{elt}"));// loop for a durationduring({ amount: 10, unit: "minutes" }).on(http("name").get("/"));during(5, "counter", false).on(http("name").get("/?counter=#{counter}"));// loop while condition holds (condition before each iteration)asLongAs("#{condition}").on(http("name").get("/"));asLongAs((session) => session.get("condition")).on(http("name").get("/"));// loop while condition holds (condition after each iteration)doWhile("#{condition}").on(http("name").get("/"));// loop while condition holds AND duration not elapsedasLongAsDuring("#{condition}", { amount: 5, unit: "minutes" }).on(http("name").get("/"));// same but condition evaluated after each iterationdoWhileDuring("#{condition}", { amount: 5, unit: "minutes" }).on(http("name").get("/"));// loop foreverforever().on(http("name").get("/"));
Gatling supports if-style and switch-style branching based on session values or arbitrary functions.
Java
JavaScript / TypeScript
// if conditiondoIf("#{condition}").then(http("name").get("/"));doIf(session -> session.getBoolean("condition")).then(http("name").get("/"));// if / elsedoIfOrElse("#{condition}").then( http("name").get("/")).orElse( http("else").get("/"));// equality checkdoIfEquals("#{actual}", "expectedValue").then(http("name").get("/"));// equality check with else branchdoIfEqualsOrElse("#{actual}", "expectedValue") .then(http("name").get("/")) .orElse(http("else").get("/"));// switchdoSwitch("#{myKey}").on( onCase("foo").then(http("name1").get("/foo")), onCase("bar").then(http("name2").get("/bar")));// switch with fallbackdoSwitchOrElse("#{myKey}").on( onCase("foo").then(http("name1").get("/foo")), onCase("bar").then(http("name2").get("/bar"))).orElse(http("other").get("/other"));// probabilistic switch (Markov chain)randomSwitch().on( percent(60.0).then(http("name1").get("/foo")), percent(40.0).then(http("name2").get("/bar")));// probabilistic switch with fallbackrandomSwitchOrElse().on( percent(60.0).then(http("name1").get("/foo"))).orElse(http("other").get("/other"));// uniform random switchuniformRandomSwitch().on( http("name1").get("/foo"), http("name2").get("/bar"));// round-robin switchroundRobinSwitch().on( http("name1").get("/foo"), http("name2").get("/bar"));
// if conditiondoIf("#{condition}").then(http("name").get("/"));doIf((session) => session.get("condition")).then(http("name").get("/"));// if / elsedoIfOrElse("#{condition}").then( http("name").get("/")).orElse( http("else").get("/"));// equality checkdoIfEquals("#{actual}", "expectedValue").then(http("name").get("/"));// equality check with else branchdoIfEqualsOrElse("#{actual}", "expectedValue") .then(http("name").get("/")) .orElse(http("else").get("/"));// switchdoSwitch("#{myKey}").on( onCase("foo").then(http("name1").get("/foo")), onCase("bar").then(http("name2").get("/bar")));// switch with fallbackdoSwitchOrElse("#{myKey}").on( onCase("foo").then(http("name1").get("/foo")), onCase("bar").then(http("name2").get("/bar"))).orElse(http("other").get("/other"));// probabilistic switchrandomSwitch().on( percent(60.0).then(http("name1").get("/foo")), percent(40.0).then(http("name2").get("/bar")));// probabilistic switch with fallbackrandomSwitchOrElse().on( percent(60.0).then(http("name1").get("/foo"))).orElse(http("other").get("/other"));// uniform random switchuniformRandomSwitch().on( http("name1").get("/foo"), http("name2").get("/bar"));// round-robin switchroundRobinSwitch().on( http("name1").get("/foo"), http("name2").get("/bar"));
In randomSwitch, percentages must sum to ≤ 100. Users who fall outside the defined ranges simply continue past the switch. Format as 60 for 60%, 33.3 for 33.3%, etc.
Any technical error (timeout, failed check) within the wrapped chain causes the virtual user to restart the block from the beginning, up to a maximum number of attempts. All failing requests are still recorded.
Java
JavaScript / TypeScript
tryMax(5).on( http("name").get("/"));// with a named countertryMax(5, "counter").on( http("name").get("/"));
Use group to cluster related requests together for reporting purposes. Groups appear as aggregated metrics in the Gatling report. Groups can be nested.
A dummy action simulates a call to a remote system — with a configurable response time and success/failure outcome — without actually making a network request. This is useful when you cannot connect to the real backend but still need business process metrics.
Java
JavaScript / TypeScript
// successful dummy action with a fixed 1000ms response timedummy("Dummy Request Name", 1000);// failed dummy with a response time from sessiondummy("Dummy Request Name", "#{responseTime}").withSuccess(false);// random response time using a Gatling EL functiondummy("Dummy Request Name", "#{randomInt(5,10)}");// dummy that also updates the sessiondummy("Dummy Request Name", 1000) .withSessionUpdate(session -> session.set("foo", "bar"));