3
votes

In jmeter cookie manager you can just clear cookies in each iteration or not.

Question But what I need is that Jmeter should clear cookies after some iteration. Eg. 2 or 3

Why? I need this beceause I dont want to overload the server with new cookie data each time. I will send 30 k request but I need just 15 k new session.

1

1 Answers

4
votes

You can do this using some scripting, i.e:

  1. Add Beanshell PreProcessor as a child of the very first HTTP Request sampler
  2. Put the following code into "Script" area:

    if (vars.getIteration() == 2) {
        sampler.getCookieManager().clear();
    }
    

    Where:

    • vars - an instance of JMeterVariables, provides access to all JMeter Variables, including current iteration number
    • sampler - an entity representing the parent Sampler for the Beanshell PreProcessor, in case of HTTP Request samplers - HTTPSamplerProxy

See How to Use BeanShell: JMeter's Favorite Built-in Component article to get started with scripting in JMeter tests.