简体   繁体   English

如何在Jmeter中的两个线程组之间共享JSessionID

[英]How to share JSessionID between two thread groups in Jmeter

For my JMeter test, I would like to login once and then navigate the reports in my application concurrently with multi-threads. 对于我的JMeter测试,我想登录一次,然后与多线程同时在我的应用程序中浏览报告。 I created two thread groups that run consecutively, the first thread group contains the login HTTP requests that is set to run with one thread. 我创建了两个连续运行的线程组,第一个线程组包含设置为与一个线程一起运行的登录HTTP请求。 The second thread group contains the HTTP requests for each report in my application, and it is set to run with 50 threads. 第二个线程组包含我的应用程序中每个报告的HTTP请求,并设置为运行50个线程。

The application is deployed on a weblogic server, and the application sessions are stateful. 该应用程序已部署在Weblogic服务器上,并且应用程序会话是有状态的。

I want to share the JsessionID generated by the first thread group through weblogic after a successful login, with the second thread group HTTP Requests. 我想与第二个线程组HTTP请求共享在成功登录后通过weblogic由第一个线程组生成的JsessionID。

the problem is that the JsessionID for each of the HTTP requests in the second thread group are unique and all different than the JsessionID of the login HTTP requests in the first thread group. 问题是第二个线程组中每个HTTP请求的JsessionID都是唯一的,并且与第一个线程组中登录HTTP请求的JsessionID都不同。 As a result, the application is failing to call the authenticate the call. 结果,应用程序无法调用对呼叫进行身份验证。

The JsessionID is embedded in the cookies inside the header. JsessionID嵌入在标头内的cookie中。 I tried extracting it from the HTTP request in the first thread Group using Regular Expression Extractor(see the attached picture) and define it in HTTP Cookie Manager, but the problem persisted. 我尝试使用正则表达式提取器从第一个线程组的HTTP请求中提取它(请参见附图),并在HTTP Cookie Manager中定义它,但是问题仍然存在。 Regular Expression Extractor config 正则表达式提取器配置

  1. There is an easier way to fetch JSESSIONID cookie value using HTTP Cookie Manager 有一种使用HTTP Cookie Manager来获取JSESSIONID Cookie值的简便方法

    • add the next line to user.properties file 将下一行添加到user.properties文件

       CookieManager.save.cookies=true 
    • restart JMeter to pick the property up 重新启动JMeter以获取属性
    • once done you will be able to access the cookie value as ${COOKIE_JSESSIONID} where required 完成后,您将可以在需要时以${COOKIE_JSESSIONID}访问Cookie值
  2. In order to make it available in 2nd thread group you need to convert it into a JMeter Property using __setProperty() function like: 为了使其在第二线程组中可用,您需要使用__setProperty()函数将其转换为JMeter属性,例如:

     ${__setProperty(JSESSIONID,${COOKIE_JSESSIONID},)} 

    and once done you will be able to access the value in 2nd thread group using __P() function as ${__P(JSESSIONID,)} 完成后,您就可以使用__P()函数${__P(JSESSIONID,)}访问第二个线程组中的值

For Reference. 以供参考。 IT WORKS: 有用:

I found a different way to complete my test and successfully suppress the cookies generated in the second thread group by the ones generated in the first thread group in order to bypass login authentication. 我找到了另一种方法来完成测试,并通过第一个线程组中生成的cookie成功抑制第二个线程组中生成的cookie,从而绕过登录身份验证。

I wrote a small bsh in the first thread group that extracts the cookie and store it in different variables. 我在第一个线程组中编写了一个小的bsh,该bsh提取cookie并将其存储在不同的变量中。 Extract cookies from the first thread group 从第一个线程组中提取Cookie

I then wrote another bsh in the second thread group to suppress the cookies by applying the generated variables 然后,我在第二个线程组中编写了另一个bsh,以通过应用生成的变量来抑制cookie

Applying cookies in the second thread group 在第二个线程组中应用cookie

Now I can log in once and navigate the reports with multi-threads all sharing the same SessionID. 现在,我可以登录一次,并使用共享相同SessionID的多线程浏览报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM