I am working with Gatling and have received this error which occurs claiming 'notStartedRefIds' is defined. I am new to Gatling and am confident that the value has been declared properly already, however I cannot see why it is not being recognised.
The code which contains reference to the value is below:
case object StudentAssignmentScenario {
private val notStartedRefIdsSession = "notStartedRefIds"
private val studentAssignmentRefIdSession = "studentAssignmentRefId"
private val endpoint: String = environmentAssignmentsUrls + "/v2/studentAssignments"
private val startAssignment = http("Start StudentAssignment")
.put(endpoint + "/${studentAssignmentRefId}/start")
.headers(getHeaderMap)
.check(status.is(200))
private val submitAssignment = http("Submit StudentAssignment")
.put(endpoint + "/${studentAssignmentRefId}/submit")
.headers(getHeaderMap)
.check(status.is(200))
private val startAndSubmitAssignments = exec { session =>
val refId = session(notStartedRefIdsSession).as[Seq[String]].apply(0)
session.set(studentAssignmentRefIdSession, refId)
}.exec(startAssignment).exec(submitAssignment)
private val startAssignments = exec { session =>
val refId = session(notStartedRefIdsSession).as[Seq[String]].apply(1)
session.set(studentAssignmentRefIdSession, refId)
}.exec(startAssignment)
def readStudentAssignments = exec(http("Get Not Started StudentAssignments")
.get(endpoint)
.headers(getHeaderMap)
.queryParamMap(Map[String, String]("inclExpired" -> "true",
"context" -> "basel",
"sort" -> "dueDate,title",
"limit" -> "25", "offset" -> "0",
"status" -> "NOT_STARTED"))
.check(status.is(200),
// save refIds
jsonPath("$.items[?(@.status == 'NOT_STARTED')].refId").findAll.optional.saveAs("notStartedRefIds")))
private val studentAssignmentWorkflow = exec(startAndSubmitAssignments)
.exec(startAssignments)
val studentAssignmentWorkflowSetup: ChainBuilder = exitBlockOnFail(
group("Student Assignment Workflow") {
studentAssignmentWorkflow
})
}
The only place you seem to be populating notStartedRefIds
is in readStudentAssignments
where you extract it from the response thanks to a jsonPath
.
However, you've configured this check as optional
meaning you expect it to sometimes not be here. If that's the case, it's not surprise it can be undefined when calling session(notStartedRefIdsSession)
.