user3204829
user3204829

Reputation: 71

Header Cookie "sid" value to a variable

I need to extract the "sid" value from Jmeter Cookie. Below is the sample jmeter header output

GET htts://example.for.com/apex/AppDashboard?jl=1`

Cookie Data:

oinfo=c3RhdHVzPURlbW8mdHlwZT0yJm9pZD0wMERRMDAwMDAwR0phQkc=; logouturl=https://example.for.com/Login; disco=Q:00DQ000000GJaBG:005Q000000NwS1U:1; autocomplete=1; sid=00DQ000000GJaBG!ARoAQPklHZykcaAaJkI9prEbHROxU2CzxRfMDGKwMGpv5rZYwOOKd_GRiVRiYVYRKFTzYk6Vg0Zu48vmM5FyFSRQ4ZPtvQzR; sid_Client=000000NwS1U000000GJaBG; clientSrc=204.14.239.161; oid=00DQ000000GJaBG; apex__eventId=a0kQ0000002FecHIAS

Request Headers:

Connection: keep-alive
Accept-Language: en-US,en;q=0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0
Referer: htts://example.for.com/apex/SecureLanding?eventId=a0kQ0000002FecHIAS
Accept-Encoding: gzip, deflate
Host: example.for.com

I need to extract the "sid" value from the cookie.

Upvotes: 7

Views: 15433

Answers (2)

Dmitri T
Dmitri T

Reputation: 168122

Another simplier option is adding a HTTP Cookie Manager which automatically handles cookies. However you need to set CookieManager.save.cookies=true property either in jmeter.properties file or by passing a corresponding parameter to JMeter startup script i.e.

jmeter -JCookieManager.save.cookies=true

After that you'll see all the cookies as JMeter Variables. The easiest way to visualize them is using Debug Sampler and View Results Tree Listener

In your case you can access your sid cookie as

${COOKIE_sid}

Other cookies can also similarly be obtained as ${COOKIE_sidClient}, ${COOKIE_clientSrc}, etc.

Upvotes: 11

jason.zissman
jason.zissman

Reputation: 2800

One option is to use a regular expression extractor on the response headers. You can do this by right clicking on your HTTP Request > Add > Post Processor > Regular Expression Extractor. Fill out the fields accordingly:

  1. Response Field to check: Headers
  2. ReferenceName: SID_VALUE
  3. Regular Expression: sid=(.*);
  4. Template: $1$
  5. Match No.: 1

If the SID exists in the cookies in the response, you can access in in other samplers/tests/etc by referencing it as ${SID_VALUE}.

Upvotes: 13

Related Questions