1

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.

  • `http(...)...` is just a static object describing the HTTP call. Unless you dug deep into Gatling and add breakpoints there, what happened was most likely that you compared those objects' creation time and the session function execution time. – George Leung Feb 12 '21 at 03:12
  • "unable to do so" is as vague as it gets, but how it went wrong is the most vital information for getting help. Can you turn on logging and post those here? – George Leung Feb 12 '21 at 03:13

1 Answers1

1

Already answered on Gatling's community mailing list.

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

Stéphane LANDELLE
  • 6,076
  • 2
  • 10
  • 12
  • This solves this particular issue, thanks! I still have another issue unfortunately related to AWS signatures not being applied properly when I try a similar codebase to the above (except with an aws signature) but I'll raise that in another post :) – Anand Patel Feb 13 '21 at 06:21