Reputation: 177
I am testing a web application.
In the navigation menu of the main page, when a node is clicked, a javascript function will be called. I look up this function, the page will set document.cookie="current_moduleId=xxxx;path=/"
before redirect to the target page.
So how can I set cookie in JMeter for every request?
Upvotes: 4
Views: 10338
Reputation: 71
For people who come across this in future, I had to use 0 or -1 for the expiry time of the cookie:
Cookie cookie = new Cookie("toto","titi","localhost","/",false,-1);
Any positive integers seemed to not set the cookie
Upvotes: 0
Reputation: 34526
Create the following pan:
In BeanShell pre processor, put :
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("toto","titi","localhost","/",false,0);
manager.add(cookie);
Note that using JSR223 PreProcessor + Groovy + Caching will be better for performances
Upvotes: 7