June 13, 2014

Distribute Cookies in JMeter

JMeter Cookie BeanShell Preprocessor

In this blog post, we will see how to set cookies across different thread groups in JMeter. Cookies are small text files that reside in your computer when you browse the internet. The browser sends the previous information that is stored in the cookie for better experience.

In performance testing, there might be a scenario where you want to replicate the cookies during testing. In JMeter, cookies can be added by right clicking on the Thread Group > Add > Config Element > HTTP Cookie Manager.

JMeter Cookie

JMeter Cookie

Distribute Cookies in JMeter

In this blog post, we will see how to distribute cookies across the threads. By writing simple code, it is possible to distribute the cookies across the thread group. For that, you need to add BeanShell pre-processors, by right clicking on the Thread Group > Add > Pre Processors > BeanShell PreProcessor.

Paste the below code into your BeanShell pre-processor as shown below.

JMeter Cookie BeanShell Preprocessor

JMeter Cookie BeanShell Preprocessor

import org.apache.jmeter.protocol.http.control .CookieManager;

import org.apache.jmeter.protocol.http.control.Cookie;

    Cookie cookie = new

Cookie("JSESSIONID",vars.get("jsessionid"),"localhost","/", false,-1);

    CookieManager manager = sampler.getCookieManager();


Do not miss any posts, subscribe now.

About NaveenKumar Namachivayam

Hi there! is a passionate and experienced Performance Test Analyst based in Chicago, USA with skill sets in Manual Testing, Test Automation, Performance Testing, and Test Estimation. He loves to learn and experiment new trends and models in Software Testing. Please stop by at his personal blogs: Excel Blog, DealsBrook,, and Affiliate Insights blog and Software Testing Memes.

Leave a Reply

Your email address will not be published. Required fields are marked *