How to pass scenarios as environment variables in gatling

I am trying to pass parameters from shell file.

: ${SingleFilter:=“Foo.getBarScenario”}

And fetch them in my simulation file.

val config_filter:String = if (System.getenv(“SingleFilter”) != null) System.getenv(“SingleFilter”) else “Foo1.getBar1”
// if I print value of config_filter here, it displays Foo.getBarScenario

val singleFiltrScns = exec(s"config_filter")

val fooUIScenario = scenario(“Foo UI Simulation”)
.exec(loginScns)
.exec(singleFiltrScns)

//but when I execute simulation gatling gives me following error
// 17:04:16.567 [ERROR] i.g.c.a.b.SessionHookBuilder$$anonfun$build$1$$anon$1 - ‘sessionHook-1’ failed to execute

Thanks in advance

This won’t work:

  • exec(s”config_filter”) is not a session hook
  • You can’t select which scenarios to execute that way

If you want to select which scenario to execute, you can do something like that :

`
val myFirstScenario = scenario("…").exec(…)

val mySecondScenario = scenario("…").exec(…)

val selectedScenario = sys.env.get(“Filter”).getOrElse(“Foo”) match { // Using a system property would be simpler…
case “Foo” => myFirstScenario
case “Bar” => mySecondScenario
}

setUp(selectedScenario.inject(…).protocols(…)

`

BUT

Why are you needs for such behaviour ?

IMO, I would be much more simple to have several simulations, each with their own scenario, than an uber Simulation with a dynamic selection of which scenario to run.

Cheers,

Pierre

Thank you very much for response

We no need to run all test scenario, then we comment/uncomment some code from our UI simulation file.

We want configure our simulation in this such way to reusable for all other accounts also.

We will also try you sent code

So please give simple solution to how to handle this.

Thanks once again.

That is doing it the hard way. There is a command-line flag for telling Gatling which simulation to run. Just use that!