Calling http in a exec session


I have a scenario, where I am calling http() inside a session like -

.exec( session =>
http("test 1)

    "${x}","${s}", "${q}"))).asJSON

When this code is executed, I do not see this 'test1' being called.

I have seen examples where people have successfully used http inside a session.
Why would this not work in my case?

All the various Gatling builders like http are executed at startup. By having one in a session function, it will get built during the scenario execution and do nothing.

For any kind of dynamic behaviour during scenario execution you need to use DSL functions such as doIf

Thank you. I now understand what this means from the document


Gatling DSL components are immutable ActionBuilder(s) that have to be chained altogether and are only built once on startup. The results is a workflow chain of Action(s). These builders don’t do anything by themselves, they don’t trigger any side effect, they are just definitions. As a result, creating such DSL components at runtime in functions is completely meaningless. If you want conditional paths in your execution flow, use the proper DSL components (doIf, randomSwitch, etc)

BUT this is still not working -

My scenario -

**val** *sce* = scenario(**"sce"**)



*   * .check(*status*.is(200))




*   * .check(*status*.is(200), jsonPath(__"$.content[*]"__).findAll.saveAs(**"pList"**)))

    .foreach(**"${pList}"**, **"content"**) {

*     * exec{ session =>

        **val** parsed = **new** ObjectMapper().readValue(session(**"content"**).as[String], *classOf*[Object])

        **val** ids = JsonPath.*query*(**“$.c”**, parsed).right.get.toList

        **val** c = ids.head.toString

        session.set(**“c”**, c)

*       * **val** ids2 = JsonPath.*query*(**“$.d”**, parsed).right.get.toList

        **val** d = ids2.head

        session.set(**“d”**, d)

*       * **val** ids3 = JsonPath.*query*(**“$.e”**, parsed).right.get.toList

        **val** e = ids3.head

        session.set(**“e”**, e)

*       * doIf(session => !session(**“d”**).asOption[String].isEmpty) {

          *println*(**“I am here "** + d)

       // Try1


//OR Try2 call directly

          _/*  http(“abc”)_

*            .post(*

*            .headers(RequestHelper.headers)*

*            .body(StringBody(RequestBody.abcBody(*

*              “${a}”, “${b}”, “${c}”)))*

_            .asJSON*/_

*       * }