在 JMeter 中的线程组之间共享 cookie 值 [英] Sharing cookie values between thread groups in JMeter

查看:26
本文介绍了在 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 set up 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.

这篇关于在 JMeter 中的线程组之间共享 cookie 值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆