Cannot Grab Command Line Arguments

I am attempting to pass in command line arguments.

mvn gatling:test -DENV=dev -Dusers=500

However, the parameters dont seem to be accessible within the application.

int users = Integer.getInteger("users",1); //defaults to 1
String envName = System.getProperty("ENV"); //null

What am I doing incorrectly? I tried to follow the docs

Do you use latest (3.8.3) version of gatling-charts-highcharts and (4.2.4) gatling-maven-plugin ?

Example Simulation:

package computerdatabase;

import io.gatling.javaapi.core.ChainBuilder;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;

public class ComputerDatabaseMavenSimulation extends Simulation {
    int nbUsers = Integer.getInteger("users", 1);
    long timePause = Integer.getInteger("pause", 2);
    HttpProtocolBuilder httpProtocol =
            http.baseUrl("https://computer-database.gatling.io");

    ChainBuilder search =
        pause(timePause)
        .exec(
            http("Home")
            .get("/")
        );

    ScenarioBuilder users = scenario("Users").exec(search);

    {
        setUp(
            users.injectOpen(atOnceUsers(nbUsers))
        ).protocols(httpProtocol);
    }
}

Maven command:

mvn gatling:test -Dgatling.simulationClass=computerdatabase.ComputerDatabaseMavenSimulation -Dusers=10 -Dpause=20

Working as designed :slight_smile:

Quick proof:

1 Like

With String:

package computerdatabase;

import io.gatling.javaapi.core.ChainBuilder;
import io.gatling.javaapi.core.ScenarioBuilder;
import io.gatling.javaapi.core.Simulation;
import io.gatling.javaapi.http.HttpProtocolBuilder;

import static io.gatling.javaapi.core.CoreDsl.*;
import static io.gatling.javaapi.http.HttpDsl.http;

public class ComputerDatabaseMavenSimulation extends Simulation {
    int nbUsers = Integer.getInteger("users", 1);
    String anyString = System.getProperty("anyString");
    HttpProtocolBuilder httpProtocol =
            http.baseUrl("https://computer-database.gatling.io");

    ChainBuilder search =
        pause(1)
        .exec(
            http(anyString)
            .get("/")
        );

    ScenarioBuilder users = scenario("Users").exec(search);

    {
        setUp(
            users.injectOpen(atOnceUsers(nbUsers))
        ).protocols(httpProtocol);
    }
}

Maven command:

mvn gatling:test -Dgatling.simulationClass=computerdatabase.ComputerDatabaseMavenSimulation -Dusers=10 -DanyString=GeMi

Quick proof:

So my versions were a little out of date.

Before:

    <gatling.version>3.7.6</gatling.version>
    <gatling-maven-plugin.version>4.1.6</gatling-maven-plugin.version>

After:

    <gatling.version>3.8.3</gatling.version>
    <gatling-maven-plugin.version>4.2.4</gatling-maven-plugin.version>

However, an error is given in IntelliJ in the pom.ml file around

      <plugin>
        <groupId>io.gatling</groupId>
        <artifactId>gatling-maven-plugin</artifactId>
        <version>${gatling-maven-plugin.version}</version> <-- error
      </plugin>

of Plugin 'io.gatling:gatling-maven-plugin:4.2.4' not found

If I need to switch to Gradle to make this better I will. I have no preference around Maven.

Plugin ‘io.gatling:gatling-maven-plugin:4.2.4’ not found

That’s an error on your side. 4.2.4 (and 4.2.5) are definitely on maven central and work as expected, see Maven Central Repository Search.

Possible issues:

  • the jar is corrupted in your local maven cache, try removing it
  • you’re in a corporate network where maven is forced to go through a maven proxy (Nexus or Artifactory) where those jars are not installed.