Cookie handling issues

I m using intellij for gatling script developments using scala.
while handling cookies im seeing this error

Not found: type CookieJar. How to fix this?

Hi @balaji,

Why do you need to access this session variable?

Did you read the documentation about cookies?

Do you need something else? What is your use case?

Cheers!

Hi
Thanks for the reply.
This is my use case

  1. I am using a POST saml request (https://<hostname.domain>/acmserver/api/saml) with some form params and in response it sets a cookie. attached screenshot

I need to get the value of acmToken cookie? I tried cookie options in documentation but im getting cookie not found error.

As visible in your screenshot, this class is private, not for end users to use. Use Gatling - HTTP Helpers instead.

Yes when i used it shows cookie not available error

  val saml = scenario("ACM Token")
    .exec(http("SP")
      // Define SP's URL.
      .post("https://xxxxxx/server/api/saml")
      .header("Content-Type", "application/x-www-form-urlencoded")
      .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36")
      .header("Accept-Encoding", "gzip, deflate, br")
      .formParam("RelayState", Configuration.relayState)
      .formParam("SAMLResponse", Configuration.saml)
  )
  .exec {
    session =>
      println(session)
      println("attributessss" + session.attributes)

     
      println( session.attributes.get("gatling.http.cookies"))
      println("xxxxx" + getCookieValue(CookieKey("acmToken")))

      session
  }

output

Some(CookieJar(Map(CookieKey(acmtoken,uat.dal-stage.flatironscloud.com,/) -> StoredCookie(acmToken=eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIxNzA3NzY3IiwiZmlyc3RuYW1lIjoiQ3JhaWciLCJuY2FnZSI6IjdBMzQ0Iiwicm9sZXMiOlsiRXh0ZXJuYWwgVmlld2VyIHJvbGUiLCJUZGRBQ01BZG1pbkRldiByb2xlIiwiVGRkUGluUG9pbnRQdWJNYW51YWxzRGV2IHJvbGUiLCJUc2REYXRhTWdyUmVsZWFzTWFudWFsRGV2IHJvbGUiXSwiaXNzIjoiaHR0cHM6XC9cL2ZsYXRpcm9uc3NvbHV0aW9ucy5jb20iLCJncm91cHMiOlsiVGRkUGluUG9pbnRWaWV3ZXJEZXYiLCJBVExfUkNDVFNVUkwwNDQyIiwiVGRkUGluUG9pbnRQdWJNYW51YWxzRGV2IiwiVHNkRGF0YU1nclJlbGVhc01hbnVhbERldiIsIlRkZEFDTUFkbWluRGV2Il0sImV4cCI6MTY2OTk4ODM3MiwiaWF0IjoxNjY5OTAxOTcyLCJsYXN0bmFtZSI6Ik1jTnV0dCIsImFwcHMiOlsicHAiLCJkbSIsImFjbSIsImFtIl19.RHfv-qALc18qeX_-QYzWYTiRCaDfXFlEJu2PE7LZckrdSIJxZwj2veYofKMKIKsk9vHUI6LpaJkRc0TdKnlQ37YW87kLm42OrIMMu-EGjiPy5VexCOqfQDkmxdAcGRzhgGGqCwcDw6GshU2GVuD7rnLqCYobXGdLhhWajUq25NY, path=/,true,false,1669901972483))))
xxxxxio.gatling.http.action.cookie.GetCookieBuilder@91e3e5b

I am not able to get this acmtoken value
acmToken=<>

getCookieValue(...) is a step (ie, it has to be run in exec block)

  val saml = scenario("ACM Token")
    .exec(http("SP")
      // Define SP's URL.
      .post("https://xxxxxx/server/api/saml")
      .header("Content-Type", "application/x-www-form-urlencoded")
      .header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36")
      .header("Accept-Encoding", "gzip, deflate, br")
      .formParam("RelayState", Configuration.relayState)
      .formParam("SAMLResponse", Configuration.saml)
    )
    .exec(getCookieValue(CookieKey("acmToken")))
    .exec { session =>
      println(session("acmToken").as[String])
    }

As shown in the documentation, getCookie is an Action that must be directly passed to exec, not something you can invoke inside a function.

I am getting this error
7
Select run description (optional)

Simulation perf.search.samlexample started…
20:55:45.976 [ERROR] i.g.h.a.c.GetCookieBuilder$$anon$1 - ‘getCookie-2’ failed to execute: Neither cookie domain nor baseUrl nor wsBaseUrl
20:55:45.988 [ERROR] i.g.c.a.b.SessionHookBuilder$$anon$1 - ‘hook-1’ crashed with ‘j.u.NoSuchElementException: No attribute named ‘acmToken’ is defined’, forwarding to the next one

======

A cookie has a domain and a path. We can default to the domain of the baseUrl if you’ve configured one, but if you don’t, you must specify it explicitly.

can you please provide an example of this to specify explicitly?

.exec(getCookieValue(CookieKey(“acmToken”)))

There are plenty of examples about how to use getCookie with a domain in the documentation.

Thanks a lot it worked.

Have another question, seems like basic ones

How do i refer a session variable from one scala file to another?

.exec(session => {
  val token = session("acmToken").as[String]
  val token2 = "Bearer " + token
  session.set("acmToken", token2)
})

I need to use acmToken variable in another class

So please, open another thread.

Thanks!

Cheers!