Hej guys,
scala is pretty new for me and I have problems as soon as a leave the gatling dsl.
In my case I call an API (Mailhog) which responds with a lot of mails in json-format. I can’t grab all the values I need with “jsonPath” I need to “regex” aswell. That leads into a map and a list which I need to iterate through and save each value.
.check(jsonPath("$[*]").ofType[Map[String,Any]].findAll.saveAs("id_map")) .check(regex("href=3D\\\\\"(.*?)\\\\\"").findAll.saveAs("url_list"))
At first I wanted to loop the “checks” but I did’nt find any to repeat them without repeating the “get”-request too. So it’s a map and a list.
- I need every value of the map and was able to solve the problem with the following foreach loop.
.foreach("${id_map}", "idx") { exec(session => { val idMap = session("idx").as[Map[String,Any]] val ID = idMap("ID") session.set("ID", ID) }) .exec(http("Test") .get("/{ID}")) })}
- I need every 3rd value of the list and make a get-request on them. Before I can do this, I need to replace a part of the string. I tried to replace parts of the string while checking for them. But it won’t work with findAll.
.check(regex("href=3D\\\\\"(.*?)\\\\\"").findAll.transform(raw => raw.replace("""=\r\n""","")).saveAs("url"))
So how can I replace a part of every string in my list and how can I make a get-request on every 3rd value in the list.
Thanks in advance
T