Getting URL parts on redirected requests

Hey guys. I’ve got a portion of my application I’m trying to stress test and it generates a unique key each time as part of the URL to represent the state of a user’s application process. The application unfortunately contains a number of redirects so I’m stumped how to get the URL parts I need. Disabling redirects is going to make the tests difficult to maintain I think. There are a LOT. For the pages I’m testing once all the redirects are done there’s no “Location” in the response so it appears as my headerRegex call is failing to get anything

My relevant Scala looks like this now for debugging which I adapted from the groups list here:

headerRegex(“Location”, “”".+""").find.saveAs(“redirectURL”)
.exec(session => { println(session(“redirectURL”).as[Seq[String]]); session })

Here are some fun logs with trace enabled I’ve paired them down:

12:22:15.727 [INFO ] i.g.h.a.HttpRequestAction - Sending request ‘request_8’: scenario ‘Test Scenario’, userId #0
12:22:16.298 [TRACE] i.g.h.a.AsyncHandlerActor -

request_8: OK

Session(Test Scenario,0,Map(gatling.http.cookies → CookieStore=Map(//release12.localhost → List(…))),1408465310071,36,List(),List(OK),List(),List())

HTTP request:
GET http://release12.localhost/path/to/applyTo/236

User-Agent: [Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:30.0) Gecko/20100101 Firefox/30.0]

HTTP response:
303 See Other
Date: [Tue, 19 Aug 2014 16:22:15 GMT]

Location: [http://release12.localhost/path/to/Application_53f363ed80ba8]
Content-Length: [0]

Content-Type: [text/html; charset=UTF-8]

12:22:16.864 [WARN ] i.g.h.a.AsyncHandlerActor - Request ‘request_8 Redirect 1’ failed : headerRegex((Location,.+)).exists() didn’t match: found nothing
12:22:16.865 [TRACE] i.g.h.a.AsyncHandlerActor -

request_8 Redirect 1: KO headerRegex((Location,.+)).exists() didn’t match: found nothing

In case anyone is interested or for future posterity, I solved this by doing the following. I’m not sure if this is the best route but it works.

.check(currentLocation.transform(s => {
val locationRegex = “”"(?<=/path/to/Application_)(\d\w+)""".r
val locationKey = locationRegex findFirstIn s

Yes, that’s the way to go.

Just one thing: you really should declare your regex OUTSIDE the closure, otherwise it gets compiled every time it’s executed.