Gatling 2 - Using Multiple Session Attributes for Scenario

Hi All,

This is something which I have been having issues with for a while now, but I thought it’s best to ask the community.

Without going into too much detail, I am testing an ASP.NET solution with scenario that does two things, Firstly, logs a user in and then navigates to a members only area and performs another action.

`

val httpConfig = HttpConfiguration.httpConfig

val userdetails = csv(“userdetails.csv”).random

val headers_0 = Map(""“Accept”"" → “”“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"”")

val enter = scenario(“Enter Test”).group(“post Test Form”) {
feed(userdetails)
exec(session => {
session.set(“viewstateLogin”, “")
session.set(“formViewState”, "
”)
session
})
.exec{http(“login_user”)
.get("/en/login/")
.check(css(""“input[name=”__VIEWSTATE"]""", “value”).saveAs(“viewstateLogin”))
}
.pause(8,10)
tryMax(2){
exec{http(“post_login_form”)
.post("""/en/login/?returnurl=""")
.headers(headers_0)
.param("""__VIEWSTATE""", “${viewstateLogin}”)
//PARAMS HIDDEN
.check(regex(""“Hi, Test.”"").exists)
}.pause(8,10)
}.exitHereIfFailed
.exec{http(“navigate_members_only”)
.get("/en/members/")
}
.exec{http(“nav_competition”)
.get("/en/members/testform/")
.check(css(""“input[name=”__VIEWSTATE"]""", “value”).saveAs(“formViewState”))
}
.pause(8,10)
.exec{http(“post_competition_form”)
.post("""/en/members/testform/""")
.headers(headers_0)
.param("""__VIEWSTATE""", “”"${formViewState}""")
//PARAMS HIDDEN
.check(regex(""“

Thankyou

”"").exists)
}
}
.exec(flushSessionCookies)

`

However, the above scenario is failing when it is run with the following message

“No attribute named ‘viewstateLogin’ is defined”

I have other scenarios that involve the same steps however, are using only one session attribute and these pass successfully.

I can only assume that there is either an issue with the chaining of my exec statements which is causing me to loose my session attributes,
or there is an issue with the way in which I am creating or retrieving the attributes themselves.
I have searched for answers but I am completely out of ideas.

Any help will be greatly appreciated

Thanks

Hi Andrew,

The source of your problem is in your first exec block.

As stated in the Gatling’s documentation, Sessions are immutable.
When you’re calling session.set(“viewstateLogin”, “"), it returns a new Session instance, with your ‘viewstateLogin’ attribute set.
The same thing goes for session.set(“formViewState”, "
”).
But the way you use it, the modified session with your custom attributes set is discarded and you’re effectively return the session unmodified.
Replace :

exec(session => {
session.set(“viewstateLogin”, “")
session.set(“formViewState”, "
”)
session
})

by :

exec(session => session.set(“viewstateLogin”, “").set(“formViewState”, "”))

And it will work.

The key is the to reuse the modified session, either by chaining the .set(…, …") calls or by the storing the modified session in a val.
As a matter of fact, this would work too :

exec(session => {
val modifiedSession = session.set(“viewstateLogin”, “")
val modifiedSession2 = modifiedSession.set(“formViewState”, "
”)
modifiedSession2
})

Cheers,

Pierre

Hi Pierre,

Thank you for your help so far, I have tried both modifications to my scenario, however, I am still seeing the same issue as posted in my original question.

Is there anything else I could post in order to help further with this problem?

Thanks,

Andy

.pause(8,10)
tryMax(2){

I think there should be a “.” before “tryMax”

There should a dot before tryMax indeed, nice noticing it Michelle :slight_smile:

There’s another one missing after the feed call at the very begging of your “post Test Form” group.

What happens is that, not being chained properly, some of the steps are silently discarded.
With the dot missing before tryMax, the exec setting your custom attributes is simply not part of your scenario…

As far as I can see, this should work once the missing dots are added.

Hi ,

i am facing one problem with the session.set within the session itself i am unable to set the attribute to session . pls find out the below code snippet.

exec(session => {
val ms = MeasurementSystem.METRIC
val pids1 = session(“vehiclepids”).as[List[PlatformIdentifier]].asJava
val pids = getVehicleEmissionReportTest.vehicleData(pids1)
val from = session(“from”).as[LocalDate]
val to = session(“to”).as[LocalDate]
val request = VehicleUtilizationProxy.createEmissionRequest(pids, from, to, ms)
val requestbody = marshalToJson(request)
println(“body value is :”+requestbody)
session.set(“requestbody”,requestbody)
println("session attributes contains requestbody is "+session.contains(“requestbody”))
session
})

problem is showing like this.

at io.gatling.app.Gatling.main(Gatling.scala)
05:14:43.494 [INFO ] i.g.h.a.HttpEngine - Warm up done
Simulation simulations.BiodieselPerformance started…
body value is :{“from”:“2016-08-23”,“to”:“2016-08-24”,“VehicleIdAndProfileIdMap”:{“entry”:[{“key”:“00000000000000000000002000161712”,“value”:“00000000000000000000000000000499”},{“key”:“00000000000000000000002000173404”,“value”:“00000000000000000000000000000498”},{“key”:“00000000000000000000002000161143”,“value”:“00000000000000000000000000000497”},{“key”:“00000000000000000000002000095133”,“value”:“00000000000000000000000000000496”}]},“measurementSystem”:“METRIC”,“parameters”:null}
session attributes contains requestbody is false
05:14:44.095 [ERROR] i.g.h.a.s.HttpRequestAction - ‘httpRequest-19’ failed to execute: No attribute named ‘requestbody’ is defined
body value is :{“from”:“2016-08-23”,“to”:“2016-08-24”,“VehicleIdAndProfileIdMap”:{“entry”:[{“key”:“00000000000000000000002000207698”,“value”:“00000000000000000000000000000499”},{“key”:“00000000000000000000002000093500”,“value”:“00000000000000000000000000000498”},{“key”:“00000000000000000000002000119144”,“value”:“00000000000000000000000000000497”},{“key”:“00000000000000000000002000044227”,“value”:“00000000000000000000000000000496”}]},“measurementSystem”:“METRIC”,“parameters”:null}
session attributes contains requestbody is false
05:14:44.098 [ERROR] i.g.h.a.s.HttpRequestAction - ‘httpRequest-19’ failed to execute: No attribute named ‘requestbody’ is defined
body value is :{“from”:“2016-08-17”,“to”:“2016-08-24”,“VehicleIdAndProfileIdMap”:{“entry”:[{“key”:“00000000000000000000002000106521”,“value”:“00000000000000000000000000000499”},{“key”:“00000000000000000000002000154340”,“value”:“00000000000000000000000000000498”},{“key”:“00000000000000000000002000223423”,“value”:“00000000000000000000000000000497”},{“key”:“00000000000000000000002000159801”,“value”:“00000000000000000000000000000496”}]},“measurementSystem”:“METRIC”,“parameters”:null}
session attributes contains requestbody is false
05:14:44.207 [ERROR] i.g.h.a.s.HttpRequestAction - ‘httpRequest-19’ failed to execute: No attribute named ‘requestbody’ is defined
05:14:44.406 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-20’ crashed with ‘java.lang.IndexOutOfBoundsException: 4’, forwarding to the next one
05:14:44.407 [ERROR] i.g.h.a.s.HttpRequestAction - ‘httpRequest-19’ failed to execute: No attribute named ‘requestbody’ is defined

please any one help on this.
Thanks in advance for your cooperation.