Setting Cookie in Jmeter

BeanShell Pre Processor

This is what the Pre Processor should have
import org.apache.jmeter.protocol.http.control.CookieManager;
import org.apache.jmeter.protocol.http.control.Cookie;
CookieManager manager = sampler.getCookieManager();
Cookie cookie = new Cookie(“<NAME>”,”<VALUE>”,”<HOST>”,”/”,false,0);

The only reason Im using a pre processor is Im not sure how else to get the
CookieManager , but I suppose there is a way . ideally I’d do this in a post
processor .


reference –



Filed under JMeter

3 responses to “Setting Cookie in Jmeter

  1. Marian

    I would like to add something that doesn’t seem that obvious from the structure. The Beanshell PreProcessor HAS to be added as a CHILD of the HttpRequest. The preprocessor sets cookies per request. Otherwise thanks for the code 🙂

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s