[Java] One scenario to share between two or more simulations

Hello!

I’m a new user of Gatling and I would like to ask about one thing. I have a scenario and I want to use it at two kinds of tests: capacity and load.

How can I achieve that? One scenario should be available to use at two or more different simulations. According to requirements I would like to perform one simulation (capacity or load) and that should be available to trigger from command line using maven

My setup:
Java 11
Maven 3.8.4
gatling-charts-highcharts 3.7.6
gatling-maven-plugin 4.1.3

Thank you in advance for your suggestions!

Scenario are constant that you can put in another class.

import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

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

public class Commons {
    
    public static ScenarioBuilder myScenario = scenario("My super scenario");
}

And you can use the same scenario in different Simulations:


import io.gatling.javaapi.core.*;
import io.gatling.javaapi.http.*;

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

public class BasicSimulation extends Simulation {

  HttpProtocolBuilder httpProtocol = http
    .baseUrl("http://computer-database.gatling.io") // Here is the root for all relative URLs
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
    .acceptEncodingHeader("gzip, deflate")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0");

  {
    setUp(Commons.myScenario.injectOpen(atOnceUsers(1)));
  }
}

Of course, you can have different injection profile in each simulation.

1 Like

Thank you very much. I thought it can’t be that simple :slight_smile: