2

I have a Gatling script with few objects that I use for my tests. One of the objects is used to authenticate users and users are passed to test using a feeder. The feeder is now defined on top in the beginning of the simulation class like this:

val feeder = csv("users.csv").circular

The feeder provides pairs of usernames and passwords. The object looks like:

object Auth {
    val login = {
        feed(feeder)
        .exec(http("get_auth_token")
             .post("/get_auth_token")
             .body(StringBody("""{
                                 "username": "${username}",
                                 "password": "${password}"
                              }""")).asJSON
            // this check extracts accessToken from JSON received in response
            .check(
             status.find.in(200,304,201,202,203,204,205,206,207,208,209),
             jsonPath("$.response_body.access.token").saveAs("accessToken"),
             jsonPath("$.response_body.refresh.token").saveAs("refreshToken")
            )
        ).exitHereIfFailed
    }
    val refreshAuthToken = {
        exec(http("refresh_auth_token")
         .post("/refresh_auth_token")
         .header("Authorization", "Bearer ${refreshToken}")
         .check(
           status.find.in(200,304,201,202,203,204,205,206,207,208,209),
           jsonPath("$.response_body.access.token").saveAs("accessToken")
         )
        ).exitHereIfFailed
    }
}

Then I have a scenario that looks like:

val myScenario = scenario("My test")
    .exec(Auth.login)
    // Do some stuff here
    .exec(Auth.refreshAuthToken)
    // Do more stuff here

Then I have a setup that runs this single scenario.

What I would like to have is additional scenario that will run alongside with the get additional scenario that will run alongside with myScenario. This scenario will also perform Auth.login, but I want it to use a different set of users - so I need to have two separate feeders that will be passed to Auth.login from scenario. Can someone suggest how this can be achieved?

alexK
  • 963
  • 1
  • 7
  • 17
  • 1
    I had a problem very similar to yours, check out my solution here http://stackoverflow.com/questions/41489143/data-from-feeder-not-available-in-scenario/41878113#41878113 – Martin Jan 26 '17 at 16:23
  • 1
    Works like a charm, thanks a lot! – alexK Jan 30 '17 at 14:14

0 Answers0