Sure,relevant code snippets are below.I am new to gatling
Defining var count and comp for resetting count =0 when we loop over a new list to capture the jsonpath
var count = new java.util.concurrent.atomic.AtomicInteger(0)
val comp = new java.util.concurrent.atomic.AtomicInteger(0)
Getting List size correctly
. exec(
session => {
val wid_id = session(“list”).as[Seq[Any]].size
session.set(“wid_id”, wid_id)
}
).exec({ session =>
// val filename = session(“filename”).asOption[String].toString
wid_id = session(“wid_id”).as[Int] //counter
println(“wid_id is”+wid_id+" ")
session})
.exec({session=>
count.set(0)
session})
Code of Interest
Looping over list
.exec({session=>
count.set(0)
session})
.repeat(“${wid_id}”){
// .foreach(“${list}”, “field”, “0”){
//resetting loop when i enter repeat loop for first time
doIf(count.equals(comp)) {
exec({session =>
println(“inside loop”)
session.set(“random”,count.set(0))})
.exec(_.set(test, “fail”))
}
exec(session => {
session.set(“field”, list(count.intValue())).set(index, “wid” + count.get())
})
.exec({ session =>
println("list element is " + list(count.intValue()) + " wid index is " + wid(count.intValue()) + " index is " + count.intValue())
session
})
.exec(http(“Fields Lookup”)
.get(“/ots/super/services/wql/v1/dataSources/${datasourceId}/fields?offset=0&limit=100”)
.headers(Map(“X-Workday-Client” → “0”, “Session-Secure-Token” → “${csrfToken}”, “Content-Type” → “application/json”
, “Authorization” → auth))
.check(
status.is(200)
).check(jsonPath(“$.data[?(@.descriptor == "${field}")].id”).find.saveAs(“wid”+count.get().toString))) //want to capture jsonPath in wid0 ,wid1 ,wid2 variables
.exec({ session =>
count.getAndIncrement()
session
})
Thanks
Sandeep