1

Below is the piece of code from Java Script(K6) that returns me Cookie. I am trying to do the same in JMeter Groovy language.

 let sso = JSON.stringify(response.request.cookies[`mygateid_sso`]);
 let authToken_regex = /{'authToken':'(\S+?)'}/;
 authToken = sso.match(authToken_regex)[0];

I am not finding a way to read response.request.cookies

Vishal
  • 339
  • 1
  • 9
  • 26

1 Answers1

1

In JMeter you have neither JSON as it's not a part of Nashorn engine nor response.request.cookies

If you want to access your mygateid_sso cookie the easiest way is:

  1. Add HTTP Cookie Manager to your Test Plan

  2. Add the next line to user.properties file (lives in "bin" folder of your JMeter installation)

    CookieManager.save.cookies=true
    
  3. Restart JMeter to pick up the change

  4. That's it, you should be able to access your cookie as ${COOKIE_mygateid_sso} where required

More information: HTTP Cookie Manager Advanced Usage - A Guide

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • Thanks, it helps. Cookie contains lots of things. Is it possible to extract token from this cookie and set it as Cookie. headers: { 'Accept': '*/*', 'Cookie': 'sso="' + authToken + '"' }, – Vishal May 25 '21 at 08:10