In a stateless internet, many sites and applications use cookies to retain a handle between sessions or to keep some state on the client side. If you are planning to use JMeter to test such web applications, then cookie manager will be required.
To learn how to enable HTTP Cookie Manager and run tests in JMeter, you can watch below video.
In this article, we will cover two topics:
If you need to extract a cookie data from response body, one option is to use a Regular Expression Extractor on the response headers.[4] Another simpler option is adding a HTTP Cookie Manager which automatically handles cookies in many configurable ways.
HTTP Cookie Manager has three functions:
Nearly all web testing should use cookie support, unless your application specifically doesn't use cookies. To add cookie support, simply add an HTTP Cookie Manager to each Thread Group in your test plan. This will ensure that each thread gets its own cookies, but shared across all HTTP Request objects.
To add the HTTP Cookie Manager, simply select the Thread Group, and choose Add → Config Element → HTTP Cookie Manager, either from the Edit Menu, or from the right-click pop-up menu.
HTTP Cookie Manager Usage & Example in JMeter (YouTube link)
In this article, we will cover two topics:
- Why cookie manager?
- Where to put cookie manager?
Why Cookie Manager
If you need to extract a cookie data from response body, one option is to use a Regular Expression Extractor on the response headers.[4] Another simpler option is adding a HTTP Cookie Manager which automatically handles cookies in many configurable ways.
HTTP Cookie Manager has three functions:
- Stores and sends cookies just like a web browser
- Each JMeter thread has its own "cookie storage area".
- Note that such cookies do not appear on the Cookie Manager display, but they can be seen using the View Results Tree Listener.
- 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" by
- Setting it in jmeter.properties file, or
- Passing a corresponding parameter to JMeter startup scrip
- jmeter -JCookieManager.save.cookies=true
- The names of the cookies contain the prefix "COOKIE_" which can be configured by the property "CookieManager.name.prefix"
- See [4] for an example
- Supports adding a cookie to the Cookie Manager manually
- 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.
Where to Put Cookie Manager
Nearly all web testing should use cookie support, unless your application specifically doesn't use cookies. To add cookie support, simply add an HTTP Cookie Manager to each Thread Group in your test plan. This will ensure that each thread gets its own cookies, but shared across all HTTP Request objects.
To add the HTTP Cookie Manager, simply select the Thread Group, and choose Add → Config Element → HTTP Cookie Manager, either from the Edit Menu, or from the right-click pop-up menu.
References
- Using the HTTP Cookie Manager in JMeter
- Understanding and Using JMeter Cookie Manager
- Adding Cookie Support
- Header Cookie “sid” value to a variable
- Using RegEx (Regular Expression Extractor) with JMeter
- JMeter: How to Turn Off Captive Portal from the Recording Using Firefox (Xml and More)
- JMeter—Use Extractors (Post-Processor Elements) for Correlation (Xml and More)
No comments:
Post a Comment