Search code examples
scalaperformance-testinggatlingscala-gatling

How to pass value between requests in the Gatling resources method?


I've got a script with multiple requests sent as resources of a main request. I need to extract value from 1 of the resources requests and pass to another. Since all this requests are executed in parallel I'm looking for an option to suspend execution of one of them until parameter will be extracted.

Here is some part of my request

.exec(http("request_2")
        .get(uri1 + "/app/botchat/botchatui.html?locale=en&personaType=1")
        .headers(headers_0)
        .resources(http("request_3")
        .get(uri1 + "/app/pots/images/logo-sm.svg")
        .headers(headers_3),
        http("request_29")
        .post(uri2 + "/bot/directline/tokens/generate")
        .headers(headers_29)
        .body(RawFileBody("package/website/0029_request.json"))
            .check(jsonPath("$.token").saveAs("token")),
        http("request_34")
        .post(uri2 + "/bot/directline/conversations")
        .headers(headers_34)
              .header("authorization","Bearer ${token}")
        .body(RawFileBody("package/website/0034_request.json")))

So I need to extract value from request_29 and pass to request_34. I've tried with session parameters but it didn't worked.

Will appreciate any help.


Solution

  • That can't work. resources are by definition asynchronous and executed concurrently so you have no guarantee request_29 completes and you can capture your token before request_34 starts.

    You have to execute request_34 sequentially after request_2, out of its resources.