I am very new to Gatling and being half made to use it I need to write automation scripts with it. I have no prior experience with it in any way.
When I am trying to run multiple scenarios I retrieve a “session_key” as part of a JSON response after a login. I tried to follow guides from the internet, saved this value but when I attempt to use it further in my second scenario the Expression Language can’t find it.
I have verified my JSONPath expression for it and it seems to be correct.
{"result":1,"resultType":"ack","output":{"session_key":"a value for the session key goes here"},"errorMessage":false,"errorCode":false,"additional":{"locationtabs":["tab 1","tab 2","tab 3"]}}
I have also listed my code below but replaced usage data with mock data for my question.
package basic
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import com.excilys.ebi.gatling.jdbc.Predef._
import com.excilys.ebi.gatling.http.Headers.Names._
import com.jayway.jsonpath._
import akka.util.duration._
import bootstrap._
class GetLocations extends Simulation
{
val httpConf = httpConfig
.baseURL("https://myURL")
.acceptCharsetHeader("ISO-8859-1,utf-8;q=0.7,*;q=0.7")
.acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3")
.disableFollowRedirect
val scn = scenario("Login Test")
.exec(
http("requestLogin")
.post("/restapi/login")
.param("username", "a username")
.param("password", "a password")
.param("client_uid", "testUid")
.check(jsonPath("$.result").is("1"))
.check(jsonPath("$.output.session_key").findAll.saveAs("session_key"))
).pause(15)
val getLocations = scenario("Get Locations")
.exec(
http("getLocations")
.post("/restapi/get_employee_favouritelocations")
.param("client_uid","testUid")
.param("clientType","automatedTest")
.param("session_key","${session_key}")
.check(jsonPath("$.result").is("1"))
)
setUp(scn.users(50).ramp(50).protocolConfig(httpConf),
getLocations.users(50).ramp(50).protocolConfig(httpConf)
)
}
Any help you can provide is appreciated as this has been giving me headaches for a week and unfortunately only i am available to work with this currently.