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