1

I am using regular expression extractor in JMeter to extract the response data which contains something like the following:

Set-Cookie: X-Tr-Auth=b1eada98-ffa1-45a3-522e-591a84dd48f2; Path=/msf; Expires=Fri, 05 Dec 2064 09:25:44 UTC; HttpOnly

The above data is sent from the server after user logs in, I need to use the above authcode to post a JSON body.

I have set the regular expression extractor to the following values:

Reference Name: authcode

Regular Expression: Set-Cookie: "(.+?)"

Template: $1$

Match No. : 1

Default Value: 0

I am getting 0 every time I run the test. I saw a similar question in Stack-overflow with no satisfactory answer. Need expert advise.

Compass
  • 5,867
  • 4
  • 30
  • 42
Powell Mittra
  • 71
  • 4
  • 15

2 Answers2

0

Try this regular expression,

Auth\=(.*); Path

with remaining settings which you have used.

In this I am expecting you need only authcode value, As Authocde label is constant no need to extract it.

Nachiket Kate
  • 8,473
  • 2
  • 27
  • 45
  • Thanks, it worked! But now I am trying to use it to POST a JSON request with header value set to Cookie X-Tr-Auth=${authcode}. But the request does not show the value. – Powell Mittra Dec 05 '14 at 10:17
  • Please upvote or accept answer if it was helpful. Check for scoping issues. If value is getting extracted successfully then it should be available with ${authocode}. – Nachiket Kate Dec 05 '14 at 10:41
  • I have set the following in HTTP Header Manager Content-Type application/json Accept-Encoding gzip,deflate,sdch Accept-Language en-US,en;q=0.8 Cookie: X-Tr-Auth=${authcode} But the request does not show any Cookie field all the other fields are shown. Am i making some mistake? – Powell Mittra Dec 05 '14 at 11:30
0

You should be able to get the cookie value without having to extract it using regex.

  1. Add CookieManager.save.cookies=true line into user.properties file which lives under /bin folder of your JMeter installation
  2. Restart JMeter if it's running (reading properties from file is not dynamic and performen on load)
  3. Add a HTTP Cookie Manager to your test plan
  4. Add a HTTP Header Manager as a child of the request you need to parametrize and configure it as follows:
    • Name: Cookie X-Tr-Auth
    • Value: ${authcode}
Dmitri T
  • 159,985
  • 5
  • 83
  • 133