Handling cookies in HTTP request in Jmeter

梦想的初衷 提交于 2019-12-24 19:22:17

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/45182634/handling-cookies-in-http-request-in-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!