0
votes

I'm trying to clear cookies for each 10 iteration for example;

if (vars.getIteration() % 10) {

    HTTPSamplerBase sampler = ctx.getCurrentSampler();
    log.info(sampler.getName());
    CookieManager cookieManager =   sampler.getCookieManager();
            log.info(cookieManager+"");
            cookieManager.clear();

     }

On first call, say iteration 10 it works fine, but on the second one the cookiemanager becomes null.

I'm running this from Beanshell post processor.

I tried to go through all cookies and remove them from cookieManager but nothing changed.

Note HTTP Cookie Manager Cookie Policy is set to Standard and Clear Cookies after Each Iteration is unchecked.

1
What's your JMeter version ? Did you tried with latest 3.3?user7294900
Can you show your plan ? otherwise it's impossible to help , thanksUBIK LOAD PACK

1 Answers

0
votes

I found this issue as well. Couldn't find any solution online.

After checking the source code, I suppose this is probably because the method clear() calls the super.clear() before clearing cookies, which clears all the CookieManager other's settings.

So I wrote the following code instead to clear the cookies only and it works for me.

import org.apache.jmeter.protocol.http.control.*
import org.apache.jmeter.testelement.property.CollectionProperty

CookieManager cm = sampler.getCookieManager()
// clear cookies and use basic auth for each user
log.info("*************** Clearing " + cm.getCookieCount() + " Cookies")
cm.setProperty(new CollectionProperty("CookieManager.cookies", new ArrayList<>()))

I am thinking to report this issue to Jmeter sometime.