I have the following setup:
Thread A
- Http Cookie Manager
- Login Page
Thread B
- Http Cookie Manager
- Page to hit
- Another page to hit
I should have been a little more clear in my question, but we got this fixed. Here is our solution:
Http Cookie Manager
Thread A - 1 Thread - 1 Loop Count
- Login Page
- BeanShell PostProcessor
- props.put("MyCookie","${COOKIE_<INSERT ACTUAL COOKIE NAME>}");
Thread B - 50 Threads - Infinite Loop Count
- BeanShell PreProcessor
- import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie("<INSERT ACTUAL COOKIE NAME>",props.get("MyCookie"),"<INSERT DOMAIN NAME>","<INSERT COOKIE PATH>",false,0);
manager.add(cookie);
- Page to hit
- Another page to hit, repeat as needed
Then there is a configuration change for JMeter needed:
Open up the jmeter.properties file and go to the line "CookieManager.save.cookies=false" and make it = true.
This will allow the login cookie in the first thread to be used in the second thread.
CookieManager
does not share cookies between threads. For some reason @ClarenceKlopfstein's method didn't work for me (jmeter 3.0). For some reason "${COOKIE_<INSERT ACTUAL COOKIE NAME>}"
didn't seemed to evaluate the string passed.
So, here's another solution to do a Login, and then pass the .ASPXAUTH
cookie. It should work without any configuration changes:
In a setUp Thread Group
(important):
BeanShell PostProcessor:
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = ctx.getCurrentSampler().getCookieManager();
Cookie cookie = manager.get(3); //Find the '.ASPXAUTH' cookie
log.info("Cookie:" + cookie);
props.put("MyCookie",cookie.getValue());
Then in a normal Thread Group:
BeanShell PreProcessor:
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie(".ASPXAUTH",props.get("MyCookie"),"<DOMAIN>","/",false,0);
manager.add(cookie);