Storing a random json return value

Dear all,

I one of my previous question I asked how I could build a generic function that knows how to manipulate the default requests outputted by the recorder. I’ve build this as suggested by Stéphane by making a generic http function. Simplified it looks as follows.

def httpInterpreted(name: String, url: EvaluatableString, headers: Map[String,String], requestBodyFile: String) =
{
def defaultHttp …
def customHttp …

requestType match
{
case “instantiate” => customHttp(List(“objecttype”))
.check(jsonPath(“$…guid”).saveAs(“guid”))
case “retrieve_by_xpath”=> customHttp(List(“xpath”, “schema”, “count”, “aggregates”))
.check(jsonPath(“$…mxobjects.guid”).find(?random?).whatever.saveAs(“guid”))

case _ => defaultHttp
}
}

I want to store one random guid of all the ones returned. I know how to do this in this way, by building a session function, but than I have to do it for every request. I think it would be need to also use some generic solution for this.

I tried passing the session to this function and retrieving the session member and editing it, but it didn’t work. My guess is the session members (in this case ${guid}), aren’t accessible only after the whole http method is executed or am I wrong?

Do you have any idea for solving this issue?

Cheers,
Roy

Why don’t you findAll of them, and pick one randomly in a transform step directly into your check? https://github.com/excilys/gatling/wiki/Checks#wiki-transforming

Didn’t know about this functionality. Great! Have a nice weekend!

You’re welcome. You too!