Passing parameters to a simulation

Use Java system properties to pass parameters to a Gatling Simulation.

You might want to pass parameters from the command line to the Simulation, for example the number of users, the duration of the ramp, etc.

In Java, Kotlin or Scala

One way is to pass Java System Properties.

The way to pass such System Properties would depend on your launcher:

  • maven: mvn gatling:test -Dusers=500 -Dramp=3600
  • gradle: gradle gatlingRun -Dusers=500 -Dramp=3600
  • sbt: sbt -Dusers=500 -Dramp=3600 Gatling/test

You can then resolve those properties directly in your code:

     
int nbUsers = Integer.getInteger("users", 1);
long myRamp = Long.getLong("ramp", 0);

setUp(scn.injectOpen(rampUsers(nbUsers).during(myRamp)));
val nbUsers = Integer.getInteger("users", 1)
val myRamp = java.lang.Long.getLong("ramp", 0)

setUp(scn.injectOpen(rampUsers(nbUsers).during(myRamp)))
val nbUsers = Integer.getInteger("users", 1)
val myRamp = java.lang.Long.getLong("ramp", 0)

setUp(scn.inject(rampUsers(nbUsers).during(myRamp)))

In JavaScript or TypeScript

The Gatling command-line tool allows you to pass options to your simulation using a key=value format:

npx gatling run users=500 ramp=3600

You can resolve these options directly in your code with the getParameter function:

import { getParameter } from "@gatling.io/core";

const nbUsers = parseInt(getParameter(
  "users", // Key used to identify the option
  "1" // Default value (optional)
));
const myRamp = parseInt(getParameter("ramp", "0"));

setUp(scn.injectOpen(rampUsers(nbUsers).during(myRamp)));

We also provide a getEnvironmentVariable function to read environment variables:

import { getEnvironmentVariable } from "@gatling.io/core";

const mySecret = getEnvironmentVariable(
  "MY_SECRET", // Name of the environment variables
  "FOO"// Default value (optional)
);

Edit this page on GitHub