djangofan
djangofan

Reputation: 29679

Cookies won't reset on iteration in JMeter 'Loop Controller'?

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

Answers (2)

Dmitri T
Dmitri T

Reputation: 168122

  1. Loop Controller doesn't increment iteration. You can test it by evaluating vars.getIteration() Beanshell code line. Iteration is being incremented on Thread Group level. To override this you can call vars.incIteration() method in any Beanshell-enabled Test Element (Sampler, Pre/Post Processor, Assertion, etc.)
  2. 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

djangofan
djangofan

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

Related Questions