Gatling 3.0.0 - Using CSV from command line to generate a dynamic scenario

Hi everyone,

I am trying to create a generic velocity tests for API’s using Gatling.

I want to pass in a string of endpoints to hit and exec each one of these for a scenario

i.e. `/api/dostuff#/api/do/otherstuff’

I can access the string in the file easily but cannot work out how to dynamically create the scenario
`

val endpoints = System.getProperty(“bendpoints”).split(“#”);

val scn = scenario(endpoints.mkString(“”))
for (e ← endpoints) {
exec(scenario(endpoints.mkString(“”))
.exec(http(“http”)
.get(e)))
}

`

And get the following as an error.

java.lang.IllegalArgumentException: requirement failed: Scenario /api/c/Keyword/blue/api/cc/keyword/red is empty
at scala.Predef$.require(Predef.scala:277)
at io.gatling.core.scenario.Simulation.$anonfun$params$4(Simulation.scala:134)
at io.gatling.core.scenario.Simulation.$anonfun$params$4$adapted(Simulation.scala:134)
at scala.collection.immutable.List.foreach(List.scala:388)
at io.gatling.core.scenario.Simulation.params(Simulation.scala:134)
at io.gatling.app.Runner.run0(Runner.scala:77)
at io.gatling.app.Runner.run(Runner.scala:61)
at io.gatling.app.Gatling$.start(Gatling.scala:74)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:47)
at io.gatling.app.Gatling$.main(Gatling.scala:39)
at io.gatling.app.Gatling.main(Gatling.scala)

I think i have the for correct but i don’t know if this is the best way to do this or if the expression is correct.

From what i can tell you cant add extra ‘exec’ steps to a scenario after it is created.

I only dip into Java + Scala when doing creating Gatling scripts which isn’t very often so any hep will be greatly appreciated.

Regards,
Aaron.

FYI for anyone else solved the issue with below

`

class VelocityTest extends Simulation {

// Splits the incomming endpoints into a java array
val endpoints = System.getProperty(“gendpoints”).split("#");
// Turns the array into a scala sequence
val endpointsSequence = endpoints.toSeq

// Defining a function that is called later
val doCall = exec(http("${endpoint}")
.get("${endpoint}"))

val scn = scenario(“Velocity Test”)
.exec(_.set(“endpoints”, endpointsSequence)) // _ is session. This sets the session variable for the endpoints
.foreach("${endpoints}", “endpoint”) { doCall } // foreach endpoint it calls the above docall function passing the endpoint

val baseUrl = System.getProperty(“thebaseUrl”);
val httpProtocol = http
.baseUrl(baseUrl)
.acceptHeader(“application/json, text/javascript, /; q=0.01”)
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.8”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.94 Safari/537.36”)

val users = Integer.getInteger(“users”, 1).toDouble;
val secondsToRun = Integer.getInteger(“secondsToRun”, 100);

setUp(scn.inject(constantUsersPerSec(users) during(secondsToRun seconds)))
.protocols(httpProtocol)
}

`