简体   繁体   English

如何使用 JSR223 PreProcessor 使用 jmeter 捕获 cookie 值?

[英]How to capture cookie value using JSR223 PreProcessor using jmeter?

The dynamic cookie parameter(token_id, access_id, state) value passed is not showingup in any response which is making difficult to capture and pass it on further request.传递的动态 cookie 参数(token_id、access_id、state)值未显示在任何响应中,这使得在进一步请求时难以捕获和传递它。 Can anybody help me with this?有人可以帮我吗?

Have you tried with the Cookie Manager available out of the box.您是否尝试过开箱即用的Cookie 管理器 It stores and sends cookies just like a web browser.它像 web 浏览器一样存储和发送 cookies。 If you have an HTTP Request and the response contains a cookie, the Cookie Manager automatically stores that cookie and will use it for all future requests to that particular web site.如果您有一个 HTTP 请求并且响应包含一个 cookie,则 Cookie 管理器会自动存储该 cookie 并将其用于该特定 web 站点的所有未来请求。 Each JMeter thread has its own "cookie storage area".每个 JMeter 线程都有自己的“cookie 存储区”。

If you want to handle the cookies using JSR223 you will have to use Post Processor.如果要使用 JSR223 处理 cookies,则必须使用后处理器。 Pre-processors are executed before sending the requests.在发送请求之前执行预处理器 Hence you do not have access to the response values within Pre-processors.因此,您无权访问预处理器中的响应值。

API Documentation will be useful if you really want to manipulate the cookies.如果您真的想操作 cookies, API 文档将很有用。

  1. The easiest option is going for HTTP Cookie Manager最简单的选择是HTTP Cookie Manager

    • Add it to your Test Plan将其添加到您的测试计划中

    • Add the next line to user.properties file (lives in "bin" folder of your JMeter installation):将下一行添加到user.properties文件(位于 JMeter 安装的“bin”文件夹中):

       CookieManager.save.cookies=true
    • Restart JMeter to pick up the change重启 JMeter 取零

    • That's it, you should be able to access your cookies as ${COOKIE_token_id} , ${COOKIE_access_id} , etc. where required就是这样,您应该能够在需要时以${COOKIE_token_id}${COOKIE_access_id}等方式访问您的 cookies

  2. If you still want to use JSR223 PreProcessor you can extract the cookies from the previous request using prev.getResponseHeaders() function, however you will need to perform some extra coding in order to:如果您仍想使用 JSR223 PreProcessor,您可以使用prev.getResponseHeaders() function 从上一个请求中提取 cookies,但是您需要执行一些额外的编码才能:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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