Different data for Different environments

I have a need to use different data for different environments like staging, integration and prod. The simulation code is the same but just that I have to change the data based on the environment I use. how can I achieve this using gatling?

Pass a system property and resolve it it your simulation to pick one file or the other.

Thanks for the lead, Stephen

I am having issues with setting the feeder file values based on my if condition.New to gatling so any help is appreciated.

I am trying to use a if statement to set the feeder file based on my environment url but I am not able to use the set value in my scenario

class X extends Simulation with TestConfiguration {
val httpProtocol = http.baseUrl("$BASE_URL") //BASE_URL is set in TestConfiguration
if(BASE_URL == “http://staging.com”)
val dataFile: String = getClass.getResource("/1.txt").getFile
val dataFile: String = getClass.getResource("/2.txt").getFile
def loadTestScenarioBuilder: ScenarioBuilder =
scenario(“POST API Tests”)
.repeat(1) {
exec(feed(csv(dataFile).random)) //this line gives an error
http(“Verify POST endpoint “)
.header(“Content-Type”, “application/json”)
.body(StringBody("""{“dataType”: “testId”, “id”: “${Id}”}""")).asJson

Doing this, I get dataFile not found error at the line where I load the feeder, exec(feed(csv(dataFile).random)). how can I make the dataFile value visible inside the loadTestScenarioBuilder?

  1. Stephen => Stéphane
  2. As you’re trying to use an if statement, you should have a look at any beginner tutorial, such as https://docs.scala-lang.org/overviews/scala-book/if-then-else-construct.html#if-expressions-always-return-a-result
  3. Why are you trying to resolve a File? You should just resolve the classpath location String and let our feeder locate it.

Thanks Stephane, if statement returning a result worked