nitish21gupta
nitish21gupta

Reputation: 21

Unable to extract session id from cookie data in jmeter

I need to get JSESSIONID from cookie data in jmeter but I am failing in doing so.

Process I am following -
In my .jmx file I have added regular expression extractor as:
- Reference Name - session_id
- Regular Expression - Cookie Data\s*:\sCMS_JSESSIONID=([^;])
- Template - $1$
- Match - 0
- Default Value - Not found

This I have added under my second url request. I am trying to extract JSESSION id from "Request" page which comes under View Results tree:

Cookie Data: CMS_JSESSIONID=8456329D51C6D7F3B924325A336CA31E

And for checking I have added debug sampler but every time result is showing "Not found".

Kindly please help.

Thanks,
Nitish

Upvotes: 1

Views: 11006

Answers (1)

Dmitri T
Dmitri T

Reputation: 168197

According to Wikipedia cookies are coming with Set-Cookie header so you need to amend your Regular Expression Extractor like:

  • Field to check: Response Headers
  • Regular Expression: Set-Cookie\s*:\sCMS_JSESSIONID=([^;])

However there is an easier way to get the cookie value (steps 1 and 2 required only once)

  1. Add CookieManager.save.cookies=true line to user.properties file
  2. Restart JMeter
  3. Add HTTP Cookie Manager to your Test Plan
  4. Access your cookie value as ${COOKIE_CMS_JSESSIONID} where required.

Upvotes: 10

Related Questions