Benj
Benj

Reputation: 289

Launch multiple scenario gatling if condition

I have two Scenarios to launch on the same times, and sometimes it's possible I want to launch only one. It's my code :

setUp(
  Scenarios.test01LoginMyPostAdmin.inject(rampUsers(1) over (30 seconds))
    .protocols(createHttpConf("mypostadmin", System.getProperty("env.current"), false)),

  Scenarios.test01LoginCiPlatform.inject(rampUsers(1) over (30 seconds))
    .protocols(createHttpConf("ciplatform", System.getProperty("env.current"), false))
)
  .assertions(global.responseTime.max.lte(15000))
  .assertions(global.successfulRequests.percent.gte(90))

I would like add a condition "IF" to launch the second scenario in the setup, because sometimes, the "System.getProperty("env.current")" value is not correct to the second scenario, and I have an exception. I don't find a function like this :

Scenarios.test01LoginCiPlatform.inject(rampUsers(1) over (30 seconds))
.doIf(condition)

Upvotes: 0

Views: 1503

Answers (1)

Gery
Gery

Reputation: 575

You could do a .doIf() in the scenario itself, not in the setUp().

val test01LoginCiPlatform: ScenarioBuilder = scenario("ScenarioName")
.doIf(condition) {
   exec(
      The rest of your scenario
   )
}

In this case your scenario starts as defined in the setUp(), but will stop if the environment variable is not found.

But an even better solution would be to fix the environment variable problem at its root.

Upvotes: 2

Related Questions