Need help on regex for correlation purpose in Gatling.

516 views
Skip to first unread message

Meenakshi Nallavalli

unread,
May 24, 2018, 2:05:32 PM5/24/18
to Gatling User Group
I do have scenario where I need to extract a dynamic value from the post request for correlation purpose and here is what it looks like 

Here I am trying to extract the dynamic value which is YTttA from the post request 

post(uri3 + "/as/YTttA/resume/as/Session.id")

Here is what my Regex looks like 

Regex :- check(regex(as="([^"]+)").saveAS("SessionID"))


Can some please let me know whether the regex format is good and is there any other way to handle this in Gatling 


Meenakshi Nallavalli

unread,
May 29, 2018, 9:07:20 AM5/29/18
to Gatling User Group
Can some one please help me out ?

danny

unread,
May 29, 2018, 11:16:33 AM5/29/18
to Gatling User Group
It would help to check the gatling implementation under the hood https://github.com/gatling/gatling

then take that regex code in the gatling api that does regex , in a driver program and test it out.

Meenakshi Nallavalli

unread,
Jun 6, 2018, 9:56:17 AM6/6/18
to Gatling User Group

Danny,

I have no luck doing correlations even after reading the doucmentation I am really looking to learn Gatling tool but not able to understand the concepts how it works ? if some one want to help please provide some sample or example scritps with basic things like parameterization, correlation, error checks, etc.,

David Miller

unread,
Jun 12, 2018, 9:10:09 AM6/12/18
to Gatling User Group
In my Gatling script I use the following, there are probably more elegant regex's to use but I did this in a rush

.exec(http("request_5")
.post("/app/login")
.headers(headers_5).check(header("Set-Cookie").saveAs("MyAppCookie")) 
.body(RawFileBody("App_0005_request.txt")).check(regex(".*?\"guid\":\"(.*?)\".*").saveAs("MyAppSessionKey")))
...
.exec(http("request_5_1")
.post("/app/${MyAppSessionKey}/subscribe")
.headers(headers_6).header("Cookie","${MyAppCookie}")

Gatling I believe uses the same RegExp syntax as Scala/Java, see e.g. https://www.tutorialspoint.com/scala/scala_regular_expressions.htm 
I use e.g. https://www.freeformatter.com/java-regex-tester.html to test my regexp is correct before editing and running my Gatling simulation.
Thanks,
Dave.

David Miller

unread,
Jun 12, 2018, 9:16:25 AM6/12/18
to Gatling User Group
If your string is literally as you have posted there (i.e. ""/as/YTttA/resume/as/Session.id") then this regex works .*?\/as\/(.*?)\/.*
Reply all
Reply to author
Forward
0 new messages