How to correlate session IDs to make the Recorder script reusable

I’m new to Gatling. How to correlate session IDs to make this script reusable? Of course, running it produces errors with the recorded Session IDs (“looking for [200-209 or 304] getting 411”). Currently 1 user (will add users after this problem solved):

package employeeClockOperation

import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
//import com.typesafe.config.ConfigFactory;

class rsClockInThenOutMinimal extends Simulation {

val httpProtocol = http
.baseURL(“http://dmilaptop101:81”)
.inferHtmlResources(BlackList("""….css""", “”"..js""", “”".*.ico"""), WhiteList())
.acceptHeader(“application/json”)
.acceptEncodingHeader(“gzip, deflate”)
.acceptLanguageHeader(“en-US,en;q=0.5”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0”)

val headers_0 = Map(
“Company-Namespace” → “”,
“Content-Type” → “application/json”,
“Geoposition” → “”,
“Kiosk-Id” → “”,
“Session-Id” → “”)

val headers_1 = Map(
“Content-Type” → “application/x-www-form-urlencoded;charset=utf-8”,
“Geoposition” → “”,
“Kiosk-Id” → “”,
“Session-Id” → “8b1f64d5-1ec0-48fa-b449-d19b719d698d”) // line 30, repeated below (line 35) & in confirmClockIn (line 88)

val headers_2 = Map(
“Geoposition” → “”,
“Kiosk-Id” → “”,
“Session-Id” → “8b1f64d5-1ec0-48fa-b449-d19b719d698d”) // repeated session ID line 35

val headers_5 = Map(
“Geoposition” → “”,
“Kiosk-Id” → “”,
“Session-Id” → “”)

val headers_7 = Map(
“Content-Type” → “application/x-www-form-urlencoded;charset=utf-8”,
“Geoposition” → “”,
“Kiosk-Id” → “”,
“Session-Id” → “6be2fb1b-0e0a-4501-962c-fd1497c88271”) // line 46, repeated below (line 51) & in confirmClockOut (line 126)

val headers_8 = Map(
“Geoposition” → “”,
“Kiosk-Id” → “”,
“Session-Id” → “6be2fb1b-0e0a-4501-962c-fd1497c88271”) // repeated session id line 51

val uri1 = “http://dmilaptop101:81/api/v0000

val scn = scenario(“rsClockInThenOutMinimal”).exec(ClockIn.clockIn, ConfirmClockIn.confirmClockIn, ClockOut.clockOut, ConfirmClockOut.confirmClockOut)
// home

object ClockIn {
// clockIn
val clockIn = exec(
http(“request_0”)
//.exec(http(“request_0”)
//.get("/")
//.pause(1)
.post("/api/v0000/employeeSessions/0/ApplicationLogOn")
.headers(headers_0)
.body(RawFileBody(“rsClockInThenOutMinimal_0000_request.txt”))
.resources(http(“request_1”)
.post("/api/v0000/clockOperation/0/StartClockIn")
.headers(headers_1),
http(“request_2”)
.get("/api/v0000/webClockHeader/0/GetHeaderInformation")
.headers(headers_2))
).pause(2)
}

object ConfirmClockIn {
// confirmClockIn
val confirmClockIn = exec(
http(“request_3”)
//.exec(http(“request_3”)
//.get("/"))
//.pause(1)
.post("/api/v0000/clockOperation/0/ConfirmEmployee")
.headers(headers_1)
.resources(http(“request_4”)
//.check(bodyString.transform(s => s.replaceAll(""", “”)).saveAs(“ClockInSessionId”))
.post("/api/v0000/employeeSessions/8b1f64d5-1ec0-48fa-b449-d19b719d698d/LogOff") //repeated session id line 88
.headers(headers_1),
http(“request_5”)
.get("/api/v0000/employeeLoginValues/4/GetInfo?companyNamespace=&applicationId=130")
.headers(headers_5))
).pause(20)
}

object ClockOut {
// clockOut
val clockOut = exec(
http(“request_6”)
//.exec(http(“request_6”)
//.get("/"))
//.pause(1)
.post("/api/v0000/employeeSessions/0/ApplicationLogOn")
.headers(headers_0)
.body(RawFileBody(“rsClockInThenOutMinimal_0006_request.txt”))
.resources(http(“request_7”)
.post("/api/v0000/clockOperation/0/StartClockOut")
.headers(headers_7),
http(“request_8”)
.get("/api/v0000/webClockHeader/0/GetHeaderInformation")
.headers(headers_8))
).pause(2)
}

object ConfirmClockOut {
// confirmClockOut
val confirmClockOut = exec(
http(“request_9”)
//.exec(http(“request_9”)
//.get("/"))
//.pause(1)
.post("/api/v0000/clockOperation/0/ConfirmEmployee")
.headers(headers_7)
//.pause(1)
.resources(http(“request_10”)
.post("/api/v0000/employeeSessions/6be2fb1b-0e0a-4501-962c-fd1497c88271/LogOff") // repeated session id, line 126
.headers(headers_7))
.resources(http(“request_11”)
.get("/api/v0000/employeeLoginValues/4/GetInfo?companyNamespace=&applicationId=130")
.headers(headers_5))
).pause(1)
}
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

Thanks in advance for any help with this!

I’m using Gatling 2.2.3

Well, record & playback brings you only so far - I assume you need to start coding

  • One API call returns the “session id” you are interested in and store it in the virtual user’s session
  • The other endpoint invocations pick up the “sessionId” and send it over the wire