Extract and save headerRegex

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:

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.

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.

But those IDs that I need can also be fount in the page’s body, so maybe I could somehow extract them from there?

EST

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.

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(0, 100)+"-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?)

Can I do it like you told me before?

.get("/delete_this_declaration-"+ThreadLocalRandom.current.nextInt(0, 100
)+"-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