Hi,
I need to get the last element returned by regex but everything what I have tried failed so far.
In my last attempt, I try to get the number of elements (count) for that regular expression, store the variable and use it in a second check
The code is
.exec(http(“Get media playlist m3u8”)
.get("${redirectURL}/${uri}")
.headers(headers_0)
.check(regex("""-video=(\S+).ts""").count.saveAs(“num_ts”))
.check(regex("""-video=(\S+).ts""").find("${num_ts}").saveAs(“ts_url”))
)
num_ts is correct and has the total number of elements but when I try to use that variable in the second check, the compiler complains:
type mismatch;
found : String("${num_ts}")
required: Int
17:20:24.265 [ERROR] i.g.c.ZincCompiler$ - .check(regex("""-video=(\S+).ts""").find("${num_ts}").saveAs(“ts_url”))
Could anyone please let me know how I could get the last element found by regex? And even the code above worked, I would need to get the “num_ts - 1”.
Thank a lot.
I don’t know if there’s a proper way to do what you ask, but something similar happened to me. In the end I’m pretty sure that you can’t use stored variables from a previous check inside the same exec (hope that Gatling devs correct me if I’m wrong).
My workaround was to execute an exec(session => session) block after saving the meaningful part from the response check, then transform the input in whatever you want. Depending on the case, you can also use the transform method, if it applies.
El dimecres, 27 juny de 2018 17:24:39 UTC+2, gon....@gmail.com va escriure:
In the end I’m pretty sure that you can’t use stored variables from a previous check inside the same exec(hope that Gatling devs correct me if I’m wrong).
Values saved from a previous check in the same check sequence are available 
Thanks for the response Stéphane.
That is what I tried but it failed because of the type mismatch. num_ts is stored as a String but find() requires a Int so I end up receiving the error
type mismatch;
found : String("${num_ts}")
required: Int
So I see two possible solutions but I could not implement yet successfully.
- Store num_ts as an Int so then I do not need to cast it from String to Int
- Store num_ts as a String and then I do the cast to Int (toInt)
I have tried that but it always failed likely because of a wrong syntax.
Could you please give me a hand with it?
Thanks a lot.