BreadcrumbHomeResourcesBlog Using The HTTP Cookie Manager In JMeter June 28, 2014 Using the HTTP Cookie Manager in JMeterOpen Source AutomationBy Daniela Sztulwark Back to topDepending on your web-application complexity, you can create JMeter test-plans of two types: hits-oriented and scenario-oriented. For creating a hits-oriented test-plan you need to have median statistics. These statistics should contain information about how many separate requests per second your application should handle. It is very simple case and it works for many web-sites. But, there are still a large number of much more complex applications. You cannot, for example, get a general report from Internet-banking using a direct link; you need to first login to the application and then navigate to certain page. For this purpose browsers store these sweetly named “cookies”, here (unfortunately) not a delicious baked good, but rather pieces of text that contain information about login sessions. JMeter also has a tool for handling these many cookies collected along the way aptly named the HTTP Cookie Manager.Table of ContentsDepending on your web-application complexity, you can create JMeter test-plans of two types: hits-oriented and scenario-oriented.The HTTP Cookie Manager element has three functions:1. The cookie manager stores and sends cookies just like a web browser.2. Received Cookies can be stored as JMeter thread variables (versions of JMeter 2.3.2+ no longer do this by default). 3. Manually add a cookie to the Cookie Manager.Table of Contents1 - Depending on your web-application complexity, you can create JMeter test-plans of two types: hits-oriented and scenario-oriented.2 - The HTTP Cookie Manager element has three functions:3 - 1. The cookie manager stores and sends cookies just like a web browser.4 - 2. Received Cookies can be stored as JMeter thread variables (versions of JMeter 2.3.2+ no longer do this by default). 5 - 3. Manually add a cookie to the Cookie Manager.Back to topThe HTTP Cookie Manager element has three functions: Back to top1. 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". So, if you are testing a web site that uses a cookie for storing information for particular sessions then each JMeter thread will have its own session. **Note that such cookies do not appear on the Cookie Manager display, but they can be seen using the View Results Tree Listener. Back to top2. Received Cookies can be stored as JMeter thread variables (versions of JMeter 2.3.2+ no longer do this by default). To save cookies as variables, define the property "CookieManager.save.cookies=true". The names of the cookies contain the prefix "COOKIE_" before they are stored (this avoids accidental corruption of local variables). To revert to the original behavior, define the property "CookieManager.name.prefix= " (with one or more spaces). If enabled, the value of a cookie with the name TEST can be referred to as ${COOKIE_TEST}. Back to top3. Manually add a cookie to the Cookie Manager. Note that if you do this, the cookie will be shared by all JMeter threads. Such cookies are created with an expiration date far in the future. A bit of practicality: the HTTP Cookie Manager in action. Let's say you have to test a bug-tracking system. The testing scenario will consist of a “Login Once Only” operation that should be performed, obviously, only once for each new user. “Creating project”, creates a new project in BTS. So we have placed the request for login into the "Only Once Controller". It means that login request will be executed only once. After that, cookies will be saved by the HTTP Cookie Manager and used for future requests. Now we’ll execute scenario one time with one user. Then we’ll switch to View Results Tree and see, whether JMeter processes cookies or not. You can see that during POST request JMeter caught cookie. Now we have to check whether this cookie is applied to following requests or not. Note that in the additional request, PHPSESSID has the same value as in the request where it was received directly from the server.HTTP Cookie Manager works as it should. No crumbs either.Learn more about JMeter through BlazeMeter UniversitySTART TESTING NOW Related Resources:HTTP Cookie Manager Advanced Usage - A GuideUsing JMeter's HTTP Header ManagerBack to top
Daniela Sztulwark Marketing and Branding Consultant Daniela has over eighteen years’ experience in marketing for high-tech startups, public and nonprofit companies. She has a proven track record in B2B brand building and market positioning for emerging and established companies and a deep passion for startups and entrepreneurship. She is hands-on and a self-starter who can define strategy and execute with limited guidance.