How to extract a parameter of a resource URL

Hello I am trying to extract a part of the a response URL
I m trying it like this

val scn = scenario(“xxx”)

.exec(http(“landing”)
.get("/")
.headers(headers_0)
.check( currentLocation.exists.saveAs(“loca”) )
.check( currentLocationRegex(".*dswid=(-?[0-9]+)").saveAs(“dswid”) )
)

//.exec{ session => println( session) ; session }
.pause(9)
.exec{ session => println( " dswid extracted: ${dwsid}"); session }
.exec{ session => println( " loc extracted: ${loca}"); session }
.exec{ session => println( session ); session }

.exec(http(“login_1”)
.post("/faces/modules/PassShop/pages/DlgStartShop.xhtml?${dwsid}")
.headers(headers_31)

Actually I am interested only in the parameter dswid but for testing purposes I also tries to store the entire location.

However the debugging code shows that neither parameter is being extracted or stored.

Can someone point out what is the problem with this code.

Here is the output of the script

https://gatling.io/docs/current/session/expression_el

This Expression Language only works on String values being passed to Gatling DSL methods. Such Strings are parsed only once, when the Gatling simulation is being instantiated.

For example queryParam(“latitude”, session => “${latitude}”) wouldn’t work because the parameter is not a String, but a function that returns a String.

Also, queryParam(“latitude”, “${latitude}”.toInt) wouldn’t because the toInt would happen before passing the parameter to the queryParam method.

The solution here would be to pass a function:

session => session(“latitude”).validate[Int].

https://gatling.io/docs/current/session/session_api/

OK, you got me confused.

I think I understand the two points in your answer.
However I do not understand how this relates to my problem.

I try to use this statement to create a new session attribute dswid

.check( currentLocationRegex(".*dswid=(-?[0-9]+)").saveAs(“dswid”) )

Here is no EL expression here.

Then later on I try to use the EL expression

.exec(http(“login_1”)
.post("/faces/modules/PassShop/pages/DlgStartShop.xhtml?${dwsid}")

Here I am using an EL Expression, but here I do pass a string

I cannot see how your answer applies to this.
And the error message
12:20:35.687 [ERROR] i.g.h.a.HttpRequestAction - ‘httpRequest-1’ failed to execute: No attribute named ‘dwsid’ is defined

indicates that the attribute could not be extracted.

Thus I tried to store the entire location in an attribute but this failed too

Neither
.check( currentLocation.saveAs(“loca”) )

nor
.check( currentLocation.exists.saveAs(“loca”) )
worked

The following three lines are only for debugging an

.exec{ session => println( " dswid extracted: ${dwsid}"); session }
.exec{ session => println( " loc extracted: ${loca}"); session }
.exec{ session => println( session ); session }

The following three lines are only for debugging an

.exec{ session => println( " dswid extracted: ${dwsid}"); session }
.exec{ session => println( " loc extracted: ${loca}"); session }
.exec{ session => println( session ); session }

This is wrong, you can’t use Gatling EL in your own function.

I kicked out the three wrong lines, but I still get an error

17:36:08.391 [ERROR] i.g.h.a.HttpRequestAction - ‘httpRequest-1’ failed to execute: No attribute named ‘dwsid’ is defined

Is there a way to print out the extracted values?

The Code

val scn = scenario(“xxx”)
.exec(http(“landing”)
.get("/")
.headers(headers_0)
.check( currentLocationRegex("(.*)").saveAs(“loca”) )
.check( currentLocationRegex(".*dswid=(-?[0-9]+)").saveAs(“dswid”) )
)

The output

Have you checked my link about the Session API?

Yes, I had read this page when tried to get started with gatling.
In I read it again just now.

Maybe my understanding is incorrect, but I don’t see how this applies to my problem.

In my code I followed more or less your tutorial script AdvancedSimulationStep03.
The major change as far as I see it is that I use a different check.

So how does the Session API fit in her.

My understanding is that with the saveAs() I can store the result of the check in session.

In your AdvancedSimulationStep03 this works
In my code it does not.

You debugging code is wrong, you can’t use Gatling EL there, you should be doing something like:

.exec{ session => println( " dswid extracted: " + session(“dwsid”).as[String]); session }

Sorry for the example, It is coming.
However your working code for the debug output helped a lot.
It showed that the correlation is working, since tje parameter loca gets save.
Thus it must be a problem with the regex.

Here comes the output and behind you find the code

.check( currentLocationRegex(".*dswid=(-?[0-9]+)").saveAs(“dswid”) )

vs

.exec{ session => println( " dswid extracted: " + session(“dwsid”).as[String]); session }

Hello,
pls try this

.check( currentLocationRegex(“dswid=([-0-9]+)”).saveAs(“dswid”) )

Thanks
Sujin Sam

Thanks all,

Now it is working.
I did in deed botched up the parameter names.

Here the final Working version of the code , still with debugging output

val scn = scenario(“xxx”)
.exec(http(“landing”)
.get("/")
.headers(headers_0)
.check( currentLocationRegex("(.*)").saveAs(“loca”) )
.check( currentLocationRegex( “.*dswid=(-?[0-9]+)”).saveAs(“dswid”) )
)

//.exec{ session => println( session) ; session }
.exec{ session => println( " loca extracted: " + session(“loca”).as[String]); session }
.exec{ session => println( " dswid extracted: " + session(“dswid”).as[String]); session }
.pause(9)

.exec(http(“login_1”)
.post("/faces/modules/PassShop/pages/DlgStartShop.xhtml?${dswid}")
.headers(headers_31)
.formParam(“DlgStartShop”, “DlgStartShop”)
.formParam(“DlgStartShop:observedDataChanged”, “false”)
.formParam(“invokedMenuName”, “MenuTopRight”)
.formParam(“invokedMenuPoint”, “mpLogin”)
.formParam(“DlgStartShop:menuControlMenuTopRight:menuPointCommand”, “”)
.formParam(“javax.faces.ViewState”, “-283852332322624722:-4391652593855092543”)
.formParam(“javax.faces.ClientWindow”, “${dwsid}”)
.formParam(“dspwid”, “${dwsid}”)
)

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)