简体   繁体   中英

Handling cookies in HTTP request in Jmeter

I have a Jmeter load project the requires retrieving 2 values of cookies and resend them in the other requests.

Here is my project test plan:

-Test Plan
-Thread Group
-Login request
-Payment page
-Payment history page
-HTTP Cookie Manager
-HTTP Header Manager
-View Results Tree

Cookie Data: JSESSIONID=0000SZb55xyLAaqLlDzumq_PpIw:-1; XSRF-TOKEN=a684e233-648e-4219-ae21-25fb362e232d

The cookie data is received successfully from the login request by cookie manager and sent in the second request (Payment page) but in the third request (Payment history page) only JSESSIONID is sent and I don't know why the second cookie is not sent in the third request.

Most probably you are not getting this cookie in Set-Cookie response header for second request therefore it doesn't get picked up by the cookie manager. If your application expects the cookie in 3rd request it might be your application issue.

As a workaround you can store the cookie value into a JMeter Variable for later re-use.

  • Add the next line to user.properties file (lives in the "bin" folder of your JMeter installation CookieManager.save.cookies=true
  • Restart JMeter to pick the property up
  • That's it, now you should be able to refer cookie value as ${COOKIE_XSRF-TOKEN} where required, for example add another HTTP Cookie Manager as a child of the 3rd request (according to Scoping Rules "local" cookie manager will override the "global" one) and define XSRF_TOKEN and other cookies if needed there)

See Using the HTTP Cookie Manager in JMeter article for more information on handling cookies in JMeter tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM