Hi there,
I need to retrieve a session ID from one http call and pass it into the simulation (either as part of the URL or as part of the message body).
After some google research, I gave up on using two scenario and turned to using before hook to retrieve the session ID. I followed the Stéphane Landelle's suggestion of using AsyncHttpClient and was able to get the json message body. But I am stuck in
1) parsing json data in the before hook
2) passing the session ID from before to scenario
Can someone show me the path? Or tell me if it's not doable?
Many thanks,
Derek
++++++++++ my test code ++++++++++
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
import org.asynchttpclient.{DefaultAsyncHttpClient, Realm}
class test extends Simulation {
val username = "+++"
val password = "+++"
before {
val client = new DefaultAsyncHttpClient()
val auth = new Realm.Builder({username}, {password})
.setScheme(Realm.AuthScheme.BASIC)
.build()
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json")
.setRealm(auth)
.execute()
val respond = future.get().getResponseBody()
client.close()
// NEED to retrieve SESSION_ID and pass to scenario below
}
val scn = scenario("gatling before test ")
.exec(http("request_1")
.get("url2/" + SESSION_ID) // need SESSION_ID from before hook
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.basicAuth({username}, {password})
)
setUp(
scn.inject(rampUsers(100) over (10 seconds)).protocols(httpConf)
)
}