Add new name/value-pair to Session

Hello,

I am very new to Scala and Gatling. I’ve been trying to figure out how to add a name/value-pair to the session object. I have learned that the session is immutable, so special handling is required to do what I need. First, what I do is get the “Location” information out of the header and save it to the session. Within that “location” string is a subjectKey that I also want to put in the session. Below is my code that is supposed to create a new subject, get its key from the response header, then use that key to delete the just created record. I just can not get the subjectKey added to the session. Any help would be greatly appreciated.

Thanks!

Hi,

 Do not create a new session object. Create a new attribute in existing session object
find comment in the code that you are supposed to change 
object Session {
    val upSession =
      exec { session => {
          val location = session.get("location").asOption[String].toString()
          val subjectKey = (location.substring(location.lastIndexOf('/') + 1)).replace(')', ' ')
          val newSession: Session = session **//Don't create this newsession object** 
          newSession.set("subjectKey", subjectKey) **// Replace this line with session.set("subjectKey", subjectKey)**
        newSession// **Return session here**
        }
      }
  }


Hope this would work

Regards

I have tried exactly what you describe - but the session object still will not have the subjecyKey added to it.

Remove the newSession from the end of the function - newSession.set already returns a session object!


object Session {
    val upSession =
      exec { session => {
          val location = session.get("location").asOption[String].toString()
          val subjectKey = (location.substring(location.lastIndexOf('/') + 1)).replace(')', ' ')
          session.set("subjectKey", subjectKey)
        }
      }
  }