POST some data before starting scenario


I’m testing a REST/JSON API and i want to play some post request before starting doing the performance test.

Here is how i’m trying to do it:

@volatile var newStudent : String = _


exec(http(“Post a student”).post(“http://localhost:8080/v1/students”).body(student)).asJSON.check(, header(“Location”).saveAs(“newStudent”)))

exec(session =>{

newStudent = session(“newStudent”).as[String]




val studentGet = scenario(“get student”)
.exec(_.set(“newStudent”, newStudent))

http(“2.Get a student “).get(”${newStudent}”).check(

setUp(studentGet.inject(rampUsers(10) over (30 seconds)).protocols(httpConf))

The before steps are never played, so the var newStudent is null

What i’m i missing ?

Thx for help

You can’t use Gatling’s DSL in before block atm.

thx for your reply.

is there a work around ?

Use a plain HTTP client. Gatling ships AsyncHttpClient.