POST some data before starting scenario

Hi,

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 = _

before{

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

exec(session =>{

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

session

})

}

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

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

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.