在JMeter中的线程组之间共享cookie值
我有以下设置:
Thread A
- Http Cookie Manager
- Login Page
Thread B
- Http Cookie Manager
- Page to hit
- Another page to hit
我一直试图将在登录页面"中设置的cookie设置为全局属性,然后将其设置为线程B中的Http Cookie管理器.但是,我一直无法正确获取它.我已经尝试了BeanShell PostProcessors之类的工具,但无法正确设置它.
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 setup correctly.
===为澄清起见添加===
=== Add for clarification ===
我无法在线程B中拥有登录页面和cookie管理器的原因是由于所需的行为.目标是登录并获取Cookie,然后一遍又一遍地打出一堆页面.这使我们能够登录一次,然后模拟该用户的大量点击.通过将cookie管理器和登录页面置于同一线程中,用户可以登录,一次打一堆页面,然后登录并再次执行.
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.
我的问题应该更清楚一些,但是我们已经解决了这个问题.这是我们的解决方案:
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
然后需要更改JMeter的配置:
Then there is a configuration change for JMeter needed:
打开jmeter.properties文件,然后转到"CookieManager.save.cookies = false"行,并将其设置为true.
Open up the jmeter.properties file and go to the line "CookieManager.save.cookies=false" and make it = true.
这将允许第一个线程中的登录cookie在第二个线程中使用.
This will allow the login cookie in the first thread to be used in the second thread.