Selecting random attribute from list captured via check.(jsonPath("$..attribute").findAll.saveAs

Hi,

I have an issue where I when I’ve captured a list of all values returned for 4 attributes in an http response:

.exec(http(“addPosition”)
.post(baseUrl + “/url/getManagePositionByARVAAjax?organisationId=${userOrgIDParam}&isARAVA=false&screenContext=OWN”)
.headers(baseHeaders)
.headers(headers_21)
.check(status.is(200))
.check(jsonPath("$…positionUuid").findAll.saveAs(“positionUuidParamList”))
.check(jsonPath("$…positionId").findAll.saveAs(“positionIdParamList”))
.check(jsonPath("$…positionName").findAll.saveAs(“positionNameParamList”))
.check(jsonPath("$…orgCodeId").findAll.saveAs(“orgCodeIdParamList”))
)

So say if there are a list of 20 values for each attribute, I want to select randomly, say value 5, for all 4 attributes to use in the next http Post, meaning that I can’t use the ${Attributename.random()} function. How do I do that? Any help would be greatly appreciated.

.exec(http(“createPositionAssignment”)
.get(baseUrl + “/url/getServerTime?_=${serverTimestamp}”)
.headers(headers_10)
.resources(http(“createPositionAssignmentRequest”)
.post(baseUrl + “/url/createPositionAssignmentRequest “)
.headers(baseHeaders)
.headers(headers_21)
.headers(headers_19)
.formParam(“applicantNotes”, “”)
.formParam(“positionExists”, “true”)
.formParam(“userPositions”, “[]”)
.formParam(“userName”, “${firstNameParam} ${lastNameParam}”)
.formParam(“userUuid”, “${newUserUUID}”)
.formParam(“workListId”, “${workListIdParam}”)
.formParam(“workListOrgId”, “”)
.formParam(“workListOrgCode”, “”)
.formParam(“workListOrgName”, “”)
.formParam(“requestType”, “OWN”)
.formParam(“organizationId”, “${orgIDParam}”)
.formParam(“changedOrgId”, “”)
.formParam(“withOutPermission”, “false”)
.formParam(“proceedWOSponsorApproval”, “true”)
.formParam(“userPositionVO[0].startDate”, “${dateString}”)
.formParam(“userPositionVO[0].endDate”, “${dateStringPlusTen}”)
.formParam(“userPositionVO[0].usersPositionId”, “”)
.formParam(“userPositionVO[0].positionName”, “${positionNameParam}”)
.formParam(“userPositionVO[0].positionUuid”, “${positionUuidParam}”)
.formParam(“userPositionVO[0].positionId”, “${positionIdParam}”)
.formParam(“userPositionVO[0].orgCode”, “${orgCodeIdParam}”)
.formParam(“userPositionVO[0].state”, “New”)
.formParam(“userPositionVO[0].source”, “CareID”)
.formParam(“userPositionVO[0].managedInId”, “1”)
.formParam(“userPositionVO[0].organizationId”, “${orgIDParam}”)
.check(
regex(“SUCCESS”).find(0).exists
)
.check(
regex(“code”:“SUCCESS”,“message”:”(.*)”,“category”)
.saveAs(“requestIdParam”)
)
))

Thanks,

Steve

The simplest solution is probably to save the whole array in the session, then extract the fields of a random entry manually in a exec(function), like:

.check(jsonPath("$…array").ofType[Seq[Any]].saveAs(“theArray”))

.exec { session =>
for {
array ← session(“theArray”).validate[Seq[Map[String, Any]]]
entry = array(Random.nextInt(array.size))
} yield session.setAll(“positionUuid” → entry(“positionUuid”), “positionId” → entry(“positionId”))
}

Thanks Stephane,

That works, although I did have to amend the check slightly:

.check(jsonPath("$[*]").ofType[Map[String,Any]].findAll.saveAs(“theArray”))

Thanks for your help!

Steve