Rahul Ganguly
Rahul Ganguly

Reputation: 2106

Gatling make one scenario run once in a chain of scenarios

I have a scenario where I have to perform certain steps. But I do not want the users to log in multiple times. So i chained the scenarios, but the login still happens multiple times. Is there any way to restrict part of the chain to run only once?

class CreateUserSimulation extends Simulation {
val login = Login.getExec()
val userCreate = UserCreate.getExec("basic")
val userJourney = scenario("User Journey")
    .exec(login)
    .exec(userCreate)

setUp(      
    userJourney.inject(constantConcurrentUsers(10) during (2 seconds))
).protocols(Params.httpProtocol)

}

Upvotes: 2

Views: 3372

Answers (1)

Amerousful
Amerousful

Reputation: 2545

You need to create a variable that will say whether or not you are in the system

val userJourney = scenario("User Journey")
.exec(_.set(isLogin, "0"))
.doIf(session => session("isLogin").as[String].equals("0")) {
  exec("login")
    .exec(_.set("isLogin", "1"))
}
.exec(userCreate)

Upvotes: 1

Related Questions