Session Variables

Is it possible to pass session variables between different classes/different scala files?

For example I have one scala file containing a class like:

class ListAllProducts extends Simulation {

def listAll (properties: Config) : ChainBuilder = {

val min=properties.getInt(“minTime”)
val max=properties.getInt(“maxTime”)

exec(http(“List All Products”)
.get("/product").check(status.is(200))
.check(jsonPath("$…*").findAll.saveAs(“listAllResponse”)))
.pause(min,max)

}

}

I was thinking this saved an attribute to the session called “listAllResponse” but I’m having trouble accessing it from another class like (this is a separate scala file):

class GetProduct extends Simulation {

def get (properties: Config) : ChainBuilder = {

val min=properties.getInt(“minTime”)
val max=properties.getInt(“maxTime”)

//here i need to get the value of listAllResponse that i saved earlier to extract some value from it before my execute below, but I can’t access it and have tried many different ways??
val list = exec( session =>{
session.attributes.get(“listAllResponse”)
session
})
//*********************************************************

exec(http(“Get Single Product”)
.get("/product/0003").check(status.is(200))
.check(jsonPath("$…*").findAll.saveAs(“listProductResponse”)))
.pause(min,max)
.exec(session => {
//println(session)
session
})

}

}

You are mixing build-time vs. run-time execution.

The first bit of code works just fine. The second bit of code is trying to access at build-time data that is created at run-time. Re-work the second part so that it is doing everything within a session-function. You will have to do things a little different than may come to mind, because you will have to communicate between bits of code by extracting and saving things to the session in one bit of code, and then use it in another.

Remember, your ChainBuilder code is executed exactly ONCE, and it is returning an object that tells Gatling how to behave.