Search code examples
gatlingscala-gatling

scala - Gatling - I can't seem to use Session Variables stored from a request in a subsequent Request


The code:

package simulations

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class StarWarsBasicExample extends Simulation
{

  // 1 Http Conf
   val httpConf = http.baseUrl("https://swapi.dev/api/films/")

  // 2 Scenario Definition
  val scn = scenario("Star Wars API")
    .exec(http("Get Number")
      .get("4")
      .check(jsonPath("$.episode_id")
      .saveAs("episodeId"))
  )
    .exec(session => {
      val movie = session("episodeId").as[String]
      session.set("episode",movie)
    }).pause(4)

    .exec(http("$episode")
      .get("$episode"))

  // 3 Load Scenario
  setUp(
    scn.inject(atOnceUsers(1)))
    .protocols(httpConf)

}

Trying to grab a variable from the first Get request, and inject that variable into a second request, but unable to do so despite using the documentation. There might be something I'm not understanding.

When I use breakpoints, and navigate through the process, it appears the session execution happens AFTER both of the other requests have been completed (by which time is too late). Can't seem to make that session execution happen between the two requests.


Solution

  • Already answered on Gatling's community mailing list.

    "$episode" is not correct Gatling Expression Language syntax. "${episode}" is correct.