0
votes

In my JMeter test plan, my app is generating two cookies "XSRF-Token" and "laravel_session". In one thread i have login request and another thread have internal pages. I have defined the HTTP COOKIES Manager at test plan level but not working. Then I have tried with BeanShell pre-processor and post-processor here is my code: Beanshell post processor in login thread:

props.put("MyCookie","${COOKIE_XSRF-TOKEN}");
props.put("MyCookie1","${COOKIE_laravel_session}");

Beanshell pre-processor in another thread:

import org.apache.jmeter.protocol.http.control.CookieManager;

import org.apache.jmeter.protocol.http.control.Cookie;

CookieManager manager = sampler.getCookieManager();

Cookie cookie = new Cookie("XSRF-TOKEN",props.get("MyCookie"),"mydomain","/",true,0);
manager.add(cookie);

Cookie cookie1 = new Cookie("laravel_session",props.get("MyCookie1"),"mydomain",/",true,0);
manager.add(cookie1);

Any idea how can I manage multiple cookies and set them so my next thread can run properly?

1
My test plan hierarchy is as follows: -Test Plan - Thread Group 1 - Login To application --Beanshell post processor(for cookies) - Thread Group 2 Beanshell pre-processor (for cookies) - Search on param 1 - Search on param 2 - results summary table - Summary reportSanjeev

1 Answers

0
votes

First, check if cookie is set with the first request using Cookie manager. If your Login request is showing the cookies in the view result tree listener. If it is not the case then probably some issue with the application. Check the second link at the bottom.

Workaround:- Add the below line to user.properties file available under bin folder

CookieManager.save.cookies=true

Restart JMeter to pick the property up

Now you should be able to refer cookie value as ${COOKIE_XSRF-TOKEN} where required, for example add another HTTP Cookie Manager as a child of the 2nd request and define XSRF_TOKEN and laravel session.

You need not to use two thread group to supply cookies from one thread group to other. Do that in a single thread group as you want to fetch cookies and supply it to the next request.

See below JMeter article for more information on handling cookies in JMeter tests. https://www.blazemeter.com/blog/using-http-cookie-manager-jmeter-not-cookie-jar https://www.blazemeter.com/blog/http-cookie-manager-advanced-usage-a-guide

Hope it helps.