我有一个Jmeter加载项目,需要检索2个cookie值,然后在其他请求中重新发送它们.
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 TreeCookie数据: JSESSIONID = 0000SZb55xyLAaqLlDzumq_PpIw:-1; XSRF-TOKEN = a684e233-648e-4219-ae21-25fb362e232d
Cookie Data: JSESSIONID=0000SZb55xyLAaqLlDzumq_PpIw:-1; XSRF-TOKEN=a684e233-648e-4219-ae21-25fb362e232d
cookie管理器已成功从登录请求中接收到cookie数据,并在第二个请求(付款"页面)中发送了cookie数据,但是在第三个请求中(付款历史"页面)仅发送了JSESSIONID,我不知道为什么第二个cookie不会在第三个请求中发送.
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.
推荐答案很可能您没有在 Set-Cookie 用于第二个请求的响应标头,因此它不会被cookie管理器接收.如果您的应用程序期望在第3个请求中使用cookie,则可能是您的应用程序问题.
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.
作为解决方法,您可以将Cookie值存储到 JMeter变量中,以供日后使用再利用.
As a workaround you can store the cookie value into a JMeter Variable for later re-use.
- 将下一行添加到 user.properties 文件(位于JMeter安装的"bin"文件夹中) CookieManager.save.cookies = true
- 重新启动JMeter以获取财产
- 就是这样,现在您应该可以在需要的地方将cookie值引用为${COOKIE_XSRF-TOKEN},例如,添加另一个 HTTP Cookie管理器作为第三个请求的子项(根据作用域规则本地" cookie管理器将覆盖全局"一个)并定义XSRF_TOKEN和其他cookie(如果需要的话)
- 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)
请参见在有关如何在JMeter测试中处理Cookie的更多信息,请参见JMeter 文章.
更多推荐
在Jmeter中处理HTTP请求中的cookie
发布评论