Dynamically Select Injection Profile for Simulation

Hello :slight_smile:

Being new to Gatling and Scala, I am facing the following challenge.

I have a base class called ParameterizedSimulation which is being extended by all of my Simulations. Its goal is to provide some parameters to my tests coming from different places. The code is the following:

class ParameterizedSimulation extends Simulation {
 // Workload model parameters
 def injectionProfile: String = getProperty("INJECTION_PROFILE", "smoke")
   ...

 private def getProperty(propertyName: String, defaultValue: String): String = {
  Option(System.getenv(propertyName))
   .orElse(Option(System.getProperty(propertyName)))
   .getOrElse(defaultValue)
 }
 
   ...
}

In addition to that, I have an object containing low-level methods (i.e. user actions) that I use in my Simulations. The code is like the following:

object UserAction {
 ...
 
 def echo(): HttpRequestBuilder = {
  http("Postman Echo Service Call")
   .get("https://postman-echo.com/get")
   .headers(headers("headers_0"))
 }

Hi there,

It doesn’t make any sense to mix closed and open workload steps.
As a consequence, they don’t share a common super type.

You should pass the scenario to your dynamicInjectionProfile method and return the result of the inject method.

Hello Stéphane,

Thanks for the quick response.

I did it as you suggested.

Thanks,
George