Reputation: 29679
Using Jmeter 2.12, what could cause the cookies to fail to reset during a JMeter Loop Controller? I've tried everything I can think of, but each time through the loop, one of the cookies from a previous login still remains. It doesn't seem to actually clear the cookies.
Here is how I put together my loop:
Thread Group 1
-- Loop Controller (3x)
-- Simple Controller
-- HTTP Header Manager
-- HTTP Cookie Manger (with 'Clear cookies each iteration?' enabled)
-- BeanShell sampler - with code that tries to clear all cookies
-- HTTP /login (gets cookies and auth headers)
-- ... various HTTP Samplers ...
-- HTTP /logout
I tried adding a Beanshell sampler with this code (as shown above) but it doesn't seem to do anything:
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.HeaderManager;
CookieManager cManager = sampler.getCookieManager();
cManager.clear();
HeaderManager hManager = sampler.getHeaderManager();
hManager.clear();
Upvotes: 7
Views: 4301
Reputation: 168122
You Beanshell code for clearing cookies actually does nothing as cManager
instance isn't being passed back to the sampler. You need to modify your code as follows:
CookieManager cManager = sampler.getCookieManager();
cManager.clear();
sampler.setCookieManager(cManager);
So sampler
could have that "cManager" instance with cleared cookies
See How to use BeanShell: JMeter's favorite built-in component guide for more information on Beanshell scripting in Apache JMeter.
Upvotes: 3
Reputation: 29679
Ok, I figured out the problem. Even though the 'HTTP Cookie Manager' has an option called 'Clear cookies each iteration', the 'iteration' it speaks of does not include a Loop Controller. What it refers to is the 'Thread Group' iterations/loops only. This was not clear and I wasted half a day until I figured this out. Wouldn't have been confusing if the checkbox said 'Clear cookies each Thread Group iteration' instead. Very disappointing.
Upvotes: 8