The cookie manager 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.
- The use of cookies eventually becomes necessary when your application has to maintain a session.
- Once you login to an application, it maintains the session of that user so that he/she can work inside the application.
- If that session is not maintained (via Cookie Manager in case of JMeter), then the user will be logged out of the application as soon as he/she sends the next request, which requires Authentication.
- You can take it like this, if your application has a session or uses cookies, then your script will not work without adding cookies in cookie manager, as then your script will not be able to maintain the session and the users (Threads) will be kicked-off the application as soon as they enter into it.
- Each JMeter thread has its cookie storage area. So, if you are testing a web site that uses a cookie for storing session information, each JMeter thread will have its session.
How to determine whether the website needs HTTP Cookie manager while writing a script
- One way is if you know about the application (which ideally a performance tester should know) that whether the application maintains any kind of session or not.
- This should be part of the Performance test planning and Requirement gathering sessions conducted before starting with the Performance testing.
- So, you should gather this information beforehand either ask the Developers, QAs working with that application.
- Another way is using any kind of developer tool like HTTPWatch, Fiddler, IE Developer Toolbar, etc. as these tools will clearly tell you that what all the cookies your application is using and which request requires which cookie.
- Using the reverse methodology (this may sound a little weird, but helpful), use View Results in Tree listener in your test plan, then without adding Cookie Manager (as at this point you don't know whether you require it or not) run your script.
- We both know that it will fail, but let it get fail. Then from the Sampler Result tab of the Tree Listener, you will get the knowledge of whether Your application is using any cookies or not? If yes, then what are the name of cookies being used?. Once you get the cookies name from there, you can add the same to your cookie manager.
- Lastly, the Thumb rule is. If your application is having any kind of session, Authentication, then you will definitely need HTTP Cookie Manager in your JMeter script.
The following example demonstrates why we need to add the cookie manager in Tests.