Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing cookie values between thread groups in JMeter

Tags:

jmeter

I have the following setup:

Thread A
  - Http Cookie Manager
  - Login Page
Thread B
  - Http Cookie Manager
  - Page to hit
  - Another page to hit

I've been trying to get the cookie that is set in the Login Page to a global property and then set it to the Http Cookie Manager in Thread B. However I've been unable to get it right. I've tried BeanShell PostProcessors and such, but haven't been able to get it set up correctly.

=== Add for clarification ===

The reason I can't have the log in page and cookie manager in Thread B is due to the behavior desired. The goal is to log in, get the cookie, and then hit a bunch of pages over and over again. This gives us the ability to log in once and then simulate a lot of hits from that user. By putting the cookie manager and log in page into the same thread the user would log in, hit a bunch of pages once and then log in and do it again.

like image 700
Clarence Klopfstein Avatar asked Mar 22 '12 15:03

Clarence Klopfstein


People also ask

How do you pass variables between thread groups in JMeter?

Pass Variables Between Thread Groups in JMeter The first thread group makes a GET request to a web service. We then use the JSON Extractor plugin to parse the JSON response. Using JSONPath, we extract the value for a particular key and save it as a JMeter variable.

How do I run multiple thread groups parallely in JMeter?

You should add multiple "Thread Group" into a "Test Plan". Inside "Test Plan" unselect "Run thread groups consecutively". Inside every "Thread Group" configure "Number of Threads(users)" as "5", "Ramp-Up Period" as "0", "Loop Count" as "1". For 5 Samplers you should need 5 "Thread Group".


1 Answers

I should have been a little more clear in my question, but we got this fixed. Here is our solution:

Http Cookie Manager
Thread A - 1 Thread - 1 Loop Count
  - Login Page
      - BeanShell PostProcessor
            - props.put("MyCookie","${COOKIE_<INSERT ACTUAL COOKIE NAME>}");
Thread B - 50 Threads - Infinite Loop Count
  - BeanShell PreProcessor 
      - import org.apache.jmeter.protocol.http.control.CookieManager;
        import org.apache.jmeter.protocol.http.control.Cookie;
        CookieManager manager = sampler.getCookieManager();
        Cookie cookie = new Cookie("<INSERT ACTUAL COOKIE NAME>",props.get("MyCookie"),"<INSERT DOMAIN NAME>","<INSERT COOKIE PATH>",false,0);
        manager.add(cookie);
  - Page to hit
  - Another page to hit, repeat as needed

Then there is a configuration change for JMeter needed:

Open up the jmeter.properties file and go to the line "CookieManager.save.cookies=false" and make it = true.

This will allow the login cookie in the first thread to be used in the second thread.

like image 109
Clarence Klopfstein Avatar answered Oct 12 '22 14:10

Clarence Klopfstein