How to pass scenarios as environment variables in gatling

684 views
Skip to first unread message

Nagesh Chinkeri

unread,
Mar 5, 2015, 5:23:58 AM3/5/15
to gat...@googlegroups.com
I am trying to pass parameters from shell file.

<content of shell file>

: ${SingleFilter:="Foo.getBarScenario"}

And fetch them in my simulation file.
<content of UI 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 

Pierre DAL-PRA

unread,
Mar 5, 2015, 5:39:21 AM3/5/15
to gat...@googlegroups.com

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

Nagesh Chinkeri

unread,
Mar 5, 2015, 6:39:22 AM3/5/15
to gat...@googlegroups.com
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. 

John Arrowwood

unread,
Mar 5, 2015, 2:07:39 PM3/5/15
to gat...@googlegroups.com
That is doing it the hard way.  There is a command-line flag for telling Gatling which simulation to run.  Just use that!
Reply all
Reply to author
Forward
0 new messages