Pages

Monday, 30 January 2017

JMeter - Config Element - "HTTP Cookie Manager"

What is Cookie?
Cookies are text files stored on the client computer and they are kept for various information tracking purpose. By default, each request is considered as a new request. In this technique, a cookie is added to the response from the servlet and it is stored in the cache of the browser. After that, if a request is sent by the user, a cookie is added to the request by default. Thus, the server recognizes the user as the old user.

How to handle cookie in Apache JMeter?
Cookies are handled in JMeter using “HTTP Cookie Manager”. Using this config element you can simulate browser activities. HTTP Cookies Manager does work in two ways:
1. Stores and sends: If an HTTP request and the response contains a cookie, then Cookie Manager automatically stores that cookie and will use it for all future requests to that particular web site. In this way, it simulates the real browser. Each JMeter thread has its own "cookie storage area". Also one more good thing in JMeter is that you can store received Cookies in a JMeter thread variable. To save cookies as variables, define the property "CookieManager.save.cookies=true". Just for a good practice you can provide cookies names are prefixed with "COOKIE_" before they are stored (this avoids accidental corruption of local variables). To revert to the original behaviour, define the property "CookieManager.name.prefix= " (one or more spaces). If enabled, the value of a cookie with the name TEST can be referred to as ${COOKIE_TEST}.
2. Add Manually: You can manually add a cookie to the Cookie Manager. However, if you do this, the cookie will be shared by all JMeter threads.  

Cookie Manager Properties: JMeter allows altering the default behaviour/configurations of cookies manager by changing its properties value for example:
  • save.cookies=true/false (set it to true if you want to keep cookies as variables)
  • check.cookies=true/false (set it to false if you want to store cross-domain cookies and might use them later)
  • name.prefix=true/false
  • delete_null_cookies=true/false

How to add "HTTP Cookie Manager" element?
You can follow the below steps:
1. Select "Test Plan" node
2. Right click on "Test Plan" node
3. Mouse hovers "Add"
4. Mouse hovers "Config Element"
5. Click "HTTP Cookie Manager"

How to remove "HTTP Cookie Manager" element?
You can follow the below steps:
1. Select "HTTP Cookie Manager" node
2. Right click on "HTTP Cookie Manager" node
3. Click "Remove" (Mouse) or "Delete" button from the keyboard
4. Click "Yes"    

What are the attributes of "HTTP Cookie Manager" element?
"HTTP Cookie Manager" has below attributes:
  • Name: To provide element name
  • Comments: To provide arbitrary comments (if any)
  • Clear cookies each iteration?: If this option is selected, then the cookie is cleared at the start of the thread. Any cookie defined in the GUI are not cleared.
  • Implementation: 
HC4CookieHandler (HttpClient 4.5.X API)
HC3CookieHandler (deprecated) (HttpClient 3 API)
The default value is HC4CookieHandler
  • Cookie Policy: The cookie policy that will be used to manage the cookies.
  • User-Defined Cookies: This option is used for adding cookie manually. This gives you the opportunity to use hardcoded cookies that will be used by all threads during the test execution. You can add the value of 'Name', 'Value', 'Domain', 'Path' and 'Secure'.  
Next Topic:
Apache JMeter - "HTTP Header Manager" Element

Previous Topic:
Apache JMeter - "HTTP Cache Manager" Element

Related Topics:

3 comments:

  1. Do we have coorelation concept in Jmeter like we have in LR?

    ReplyDelete
    Replies
    1. Yes, in JMeter dynamic values are handled by Regular Expression Extractor or Boundary Extractor element.

      Regular Expression Extractor: https://perfmatrix.blogspot.com/2017/01/apache-jmeter-regular-expression-extractor-postprocessor.html

      Boundary Extractor: https://perfmatrix.blogspot.com/2017/01/apache-jmeter-boundary-extractor-postprocessor.html

      Delete