简体   繁体   中英

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. Can anybody help me with this?

Have you tried with the Cookie Manager available out of the box. It stores and sends cookies just like a web browser. 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. Each JMeter thread has its own "cookie storage area".

If you want to handle the cookies using JSR223 you will have to use Post Processor. 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.

  1. The easiest option is going for 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):

       CookieManager.save.cookies=true
    • Restart JMeter to pick up the change

    • That's it, you should be able to access your cookies as ${COOKIE_token_id} , ${COOKIE_access_id} , etc. where required

  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:

    • extract Set-Cookie header value
    • extract the cookies you're looking for from that header 在此处输入图像描述

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