Advance Usage of Https Cookies
Posted By : Richa Sharma | 31-May-2021
Modern applications are becoming complex day by day, and most of them use cookies to store at least some user information. The most common usage is for storing user session information. Apache JMeter has a powerful config element, the HTTP Cookie Manager, to handle the storing automatically. Simultaneously , the Cookie Manager also has a variety of features and properties for handling other tasks as well. Some of the advanced uses of the JMeter Cookie Manager will be described in this blog post.
Creating a Basic Script with Jmeter cookie manager
- Add a thread group
Test plan -> Add -> Thread (Users) -> Thread Group
Set the Value to 2 in the loop count field because in order to show the cookies passing through iterations.
- Add the Http Cookies manager Element
Thread (Users) -> Add -> Config Element -> HTTP Cookie Manager
- Add an Https request which opens the Login Page
Thread Group -> Add -> Sampler -> HTTP Request
Fill in the following values:
- Name: Login page
- Server Name or IP: Stage.oodleslab.com
- Path: zuul/api/v1/auth/[email protected]&password=Dash@123&rememberMe=false
- Add another request which opens the Reset Password Page
Thread Group -> Add -> Sampler -> HTTP Request
Required values:
- Name: Reset password page
- Server Name or IP: blazedemo.com
- Path: password/reset
- Add a Listener
Thread Group -> Add -> Listener -> View Results Tree
As we check the cookie data of each request. The ‘Login page’ request on the first iteration has no cookies. All the other requests have cookie data in the request header. This means that the cookie is passing from the response to the next request, and it isn’t cleared when a new iteration starts.
The HTTP Cookie Manager Config Element
Custom cookies
User-Defined Cookies are an interesting feature made possible with the HTTP Cookie Manager. Saved cookies in this section are added to each request in the current Thread Group. It is valuable for passing information to the server. For example, you can pass the name of the Test script with custom cookies. In such a case you could distinguish JMeter script requests from the real users on the server.
- Add a row to the User-Defined Cookies section of the HTTP Cookie Manager config element.
Fill in the following parameters:
- Name: TEST
- Value: RICHACOOKIE
- Domain: stage.oodleslab.com
- Run the Script
All requests have a cookie with the name ‘TEST’ and the value ‘RICHACOOKIE’.
Cookie Manager Properties
-
CookieManager.allow_variable_cookies property
This property defines if a variable is allowed in the User-Defined cookies section. This can be used to provide information to the server. For example, by sending a request with cookies that contain a local date/time, the server can identify the local time of the user.
Example
Set the value of the custom cookie to ‘${__time(EEE\, d MMM yyyy)}’ in the User-Defined Cookies section.
When CookieManager.allow_variable_cookies=true, the value will be interpreted as a variable.
When CookieManager.allow_variable_cookies=false, the value will be interpreted as a string.
- CookieManager.save.cookies property
This property defines if cookies are stored as variables. This property can be used to get information from server cookies, to make the script more sophisticated. This also depends on the scenario, obviously. For example, let’s say the purpose of a script is to run a load test when the system has 1000 items created. Cookies from the server have information about the number of created items in the system.
Example :
Add a parameter to the ‘Login”’ request.
Fill in the values:
- Name: VAR
- Value: ${COOKIE_XSRF-TOKEN}
When CookieManager.save.cookies=true, the variable VAR has the value of the XSRF-TOKEN cookie.
When CookieManager.save.cookies=false, the variable VAR has the string value ‘${COOKIE_XSRF-TOKEN}’.
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Richa Sharma
Richa is a Self motivated , hard-working and optimistic individual. She has good analytical and scenario building skills. Richa spends her free time solving logical reasoning and sketching.