how do i set data into session and use session data in my request

Hi Stephene,

help me please,

i have some lines of code which is useful to store some data into session,

but i am unable to store data into session,

and based on the session data,i request for some other data through url like bellow (in request processing there i am using session data) ,

val dataVo=voMethod.getVos()val compData=new HashMapList[String],List[String]

val dataKey=100

val scn2=scenario("").exec(session => {
import io.gatling.http.cookie._
val newSession = (session(“gatling.http.cookies”).asOption[CookieJar].flatMap { cookieJar =>
val cookie = cookieJar.get(URI.create("[")).find(_.getName == compData)“Key”+dataKey,com****pData)) ------------------------------------------------------------------------------------------i am getting error here while set data into session


val httpProtocol = http
.userAgentHeader(“Mozilla/5.0 (Windows NT 6.1; rv:32.0) Gecko/20100101 Firefox/32.0”)

val scn = scenario(“scenario”)

setUp(scn.inject(atOnce(1 user))).protocols(httpProtocol)

Your code won’t work. You can’t do the session.set() inside of the cookie map. Not like that, anyway.

Instead, you need to define a “var newSession = session” and where you do the assignment, do “newSession = newSession.set( … )” and at the end, return newSession.

The reason is that a session is immutable. When you call .set() it is returning a new object. Calling set over and over is creating many new objects, rather than doing what you want, which is adding many things to the one session object.