Chuck
Chuck

Reputation: 998

Conditionals based on Gatling scenarios

I'd like to know if conditionals (based on scenarios) are possible in Gatling.

I have a login post in Gatling 2.1.7 like so:

.exec(http("User login")
            .post("/api/user_login")
            .headers(Headers.headers_1))

Along with a couple scenarios:

val user1 = scenario("user1").exec(
    Action.login,
    Action.addDocument,
    Action.logout
)
val user2 = scenario("user2").exec(
    Action.login,
    Action.deleteDocument,
    Action.logout
)

setUp(
    user1.inject(atOnceUsers(1))
    user2.inject(atOnceUsers(1))
).protocols(httpProtocol)

Each user has separate login credentials (in the header), and is able to interact with the app in only certain ways.

So (in pseudo code) does Gatling support something like this?

.exec(http("User login")
            .post("/api/user_login")
            .doIf(scenario == "users1") {
                .headers(Headers.headers_1) // login info for user1
            }
            .doIf(scenario == "users2") {
                .headers(Headers.headers_2) // login info for user2
            })

Upvotes: 0

Views: 1691

Answers (1)

Meiko Rachimow
Meiko Rachimow

Reputation: 4724

It is possible to get the scenarioName from the io.gatling.core.session.Session:

http("User login")
    .post("/api/user_login")
    .headers(if(session.scenarioName.equals("user1")) Headers.headers_1 else Headers.headers_2) 
  session

But it could be an option for you, to use parameters for you actions:

def login(header: Map[String, String]) = {
  http("User login")
    .post("/api/user_login")
    .headers(header)
}
//...
Action.login(Headers.headers_1),

Upvotes: 1

Related Questions