Question

I'm trying to use Gatling to test my API but I've got a problem. I'm testing for now the login/logout. At the login, the user got a token, that is used for logout.
When I use the recorder, it keep a fix token, and of course, it doesn't work when I run the test. But I don't find in the doc or google how I can get dynamically the token.
Does anyone know ?
Thanks !

EDIT:

after recording here what I got

val headers_13 = Map(
        "Accept" -> """*/*""",
        "Origin" -> """http://site.com""",
        "token" -> """token"""
)

val scn = scenario("Scenario Name")
        .exec(http("request_1")
                    .post("http://site.com/login")
                    .headers(headers_1)
                        .param("""player[email]""", """email@address.com""")
                        .param("""player[password]""", """password""")
            )
        .pause(757 milliseconds)

.exec(http("request_13")
                    .get("http://site.com/logout")
                    .headers(headers_13)
            )
        .pause(202 milliseconds)

I try to put the two pieces of code after .post("http://site.com/login") and .get("http://site.com/logout") but that didn't works

Was it helpful?

Solution

Where is your token? Is it a HTTP header? Generally speaking, the way to save data from responses in order to reuse it for further requests is the Check API.

.check(header("tokenName").saveAs("token")    
...    
.header("tokenName", "${token}")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top