Extract and save headerRegex

2,115 views
Skip to first unread message

Andrei Proskurin

unread,
Jul 1, 2014, 8:29:12 AM7/1/14
to gat...@googlegroups.com
Hi,

For example, I have a response header kmd2/?0&ssoUserId=43009090226&ssoSessionId=-12380191319559002277917559&ssoOrgUnit=1642217&ssoOrgUnit like this. Will I be able to capture ssoUserId, ssoSessionId, ssoOrgUnit using the following:

---
.check(headerRegex("Location", """kmd2\/\?0\&ssoUserId\=${ssoUserId}\&ssoSessionId\=${ssoSessionId}\&ssoOrgUnit\=${ssoOrgUnit}\&ssoOrgUnit))"""
---

Thanks that you are here for us.

Stéphane Landelle

unread,
Jul 1, 2014, 9:52:32 AM7/1/14
to gat...@googlegroups.com
No, that's not how it works, you have to pass a proper regular expression, then save what's been captured.

For multiple capture groups, you'll have to use latest snapshot. Otherwise you'll have to use several single capture group regexs.

With current snapshot:

// capture several elements into a Tuple3
.check(headerRegex("Location", "foo()bar()baz()qix").ofType[(String, String, String)].saveAs("headerExtracts"))


// this is not very convenient for now, have to expose Tuple content to access it, see https://github.com/excilys/gatling/issues/1991
.exec(session =>
  session("headerExtracts").validate[(String, String, String)].map { case (ssoUserId, ssoSessionId, ssoOrgUnit) =>
     session.setAll("ssoUserId" -> ssoUserId, "ssoSessionId" -> ssoSessionId, "ssoOrgUnit" -> ssoOrgUnit)
  }
)

But then, do you really need this? Gatling knows how to follow redirects.


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andrei Proskurin

unread,
Jul 1, 2014, 9:58:39 AM7/1/14
to gat...@googlegroups.com
So there is no easy way to do this. I thought about setting a scenario where users use to system to add new things to database and change them. The website works this way: after you enter, every link includes sessionid, and userid and so on from the first response. So I clearly cannot just record the scenario using the recorder. I thought about extracting the values but with current skills of Gatling i'm so lost, that I cannot do anything by myself (although I already read through the documention a couple of times). Maybe you could give any advice how could I get better with it.

Andrei Proskurin

unread,
Jul 1, 2014, 10:04:53 AM7/1/14
to gat...@googlegroups.com
But those IDs that I need can also be fount in the page's body, so maybe I could somehow extract them from there?

<a class="active" wicket:id="goET" href="./?0-1.ILinkListener-headerPanel-goET&amp;ssoUserId=43009090226&amp;ssoSessionId=-1237393822637000537791866&amp;ssoOrgUnit=1642217&amp;ssoOrgUnit">EST</a>


On Tuesday, July 1, 2014 4:52:32 PM UTC+3, Stéphane Landelle wrote:

Stéphane Landelle

unread,
Jul 1, 2014, 10:11:56 AM7/1/14
to gat...@googlegroups.com
As I said, the easiest way for a beginner for now is to have 3 checks, each with 1 single capture group, saving "ssoUserId", "ssoSessionId" and "ssoOrgUnit". Then you can use those values is your urls with a standard Gatling EL expression.

Andrei Proskurin

unread,
Jul 1, 2014, 10:35:25 AM7/1/14
to gat...@googlegroups.com
Ok I understood this one thanks. Although would like to ask another brief question. It is a bit connected to my previous question. If I put, for example, number of users 200 and I create a test where each user enters some website with a list where each element is like from 1 to 100. After recording the scenario each user click the same link, but I want them to be random. Can I do it like you told me before?

.get("/delete_this_declaration-"+ThreadLocalRandom.current.nextInt(0100)+"-delete")

So now will each user click on a random link /delete_this_declaration4(or5or58..)-delete" ?

Also how can I monitor such requests. I found in some other question that you can log such things with session. Like here
https://groups.google.com/forum/#!msg/gatling/nz4ErIta1LE/IpvuQC20jNcJ

You can use

.exec(
    (s:Session) => println(s.getAttribute("myKey")); s
)

 to debug. But I couldn't get this to work. Where should I put this command. And where should I see the values. (is it terminal if i run it from there?)

Stéphane Landelle

unread,
Jul 1, 2014, 11:02:15 AM7/1/14
to gat...@googlegroups.com

Can I do it like you told me before?

.get("/delete_this_declaration-"+ThreadLocalRandom.current.nextInt(0100)+"-delete")

I explicitly told you that this was WRONG and you had to pass a lambda.

 


So now will each user click on a random link /delete_this_declaration4(or5or58..)-delete" ?

Also how can I monitor such requests. I found in some other question that you can log such things with session. Like here
https://groups.google.com/forum/#!msg/gatling/nz4ErIta1LE/IpvuQC20jNcJ

You can use

.exec(
    (s:Session) => println(s.getAttribute("myKey")); s
)

 to debug. But I couldn't get this to work.

This is for Gatling 1. If you're using Gatling 2, check this page for upgrading instructions: https://github.com/excilys/gatling/wiki/Gatling%202

Reply all
Reply to author
Forward
0 new messages