Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get auth token in Gatling

Tags:

gatling

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 protected]""")
                        .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

like image 724
Simon Avatar asked Apr 19 '13 10:04

Simon


1 Answers

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}")
like image 118
Stephane Landelle Avatar answered Dec 28 '22 21:12

Stephane Landelle