How to use an EL value inside a transform or non gatling function

I’m using a feeder to check results with json. But the json that comes back is in a String. So I have to use this,
jsonPath("$.jsonData").ofType[String].transform( (s: String) => collectValue("$.Result_1.Row[0].records.Row[0].number)}).is(“1”), to put it into valid json. But the problem is, when I use the feeder instead of $.Result_1.Row[0].records.Row[0].number, the result is not valid json. So the function collectValue throws an error.

def collectValue(path: String, inputJsonString: String) : Object = {
// take in “${path}” – feeder object
println(“path=======================>” + path)
println(“inputJsonString=======================>” + inputJsonString)
val jsonObj = (new ObjectMapper).readValue(inputJsonString, classOf[Object])

val res = JsonPath.query(path, jsonObj) match {
case Right(x) => x.toVector(0)
case Left(x) => “error FROM COLLECT VALUE”
}

res.asInstanceOf[AnyRef]
}

val theProblem =

repeat(ansrFeeder.records.length, “n”) {
feed(ansrFeeder)

.exec(http("")
.get(uri2 + “”)
.headers(headers))

.pause(18)

.exec(http("")
.get(“website”)
.headers(headers)
.asJSON
.check(
jsonPath("$.jsonData").ofType[String].saveAs( “x” )
)
.check(
jsonPath("$.jsonData").ofType[String].transform( (s: String) => collectValue("$path1", s) ).is("${item1}")
))}

I’ve looked around and I think what I’m doing is possible but I can’t say for certain. I believe it’s due to the transform because ${item1} works as intended. If it’s not because of the transform then what would be the solution to using the value in a non gatling function altogether? Is it possible to compile an EL value before sending it off to a function? I’ve seen what I thought were workarounds but I couldn’t put two and two together for my problem.

Thank you,

  • Shane

Update: Sorry about not writing what version I’m using. I’m using Gatling 2.2.5. And I’ve begun trying to follow this link https://stackoverflow.com/questions/26344554/getting-the-string-out-of-a-gatling-expression
but I’m unable to remake mine into the aforementioned. The most I know is that the path being sent in is a ChainBuilder(List(io.gatling.core.action.builder.SessionHookBuilder@111xx22))

This is what I currently have trying the aforementioned strategy.

.check(
jsonPath("$.jsonData").ofType[String].transform( (s: String) => {

def makepath(path: String) = {

println(“pathinmakepath=============>”+path)
val p = (path).el[String]
println(“pinmakepath=============>”+p)

def createPath = p.map { resolvedPath =>
resolvedPath
}
println(“createPath=============================>”+createPath)
exec( {session =>
println(“insidesessioncreatepath==========================>”+(createPath))
session
})
}
collectValue(makepath("$path1").toString, s) } ).is(“5”)
)

I also tried using .body(StringBody("""{ “path1”:"${path1}",
“path2”:"${path2}"
}""")).asJSON but I was unable to figure out how to use the path1 and path2 inside collectValue.

Inside of collectValue I added

val p2 = (path).el[String]

but all this does is return (function1) when I println. I’m not entirely sure what that means.