简体   繁体   English

我如何从 Jmeter 中的另一个线程接收变量

[英]How i can receive variable from another thread in Jmeter

in the first thread, I received JSON (format - {"id":6054,"name":"Jmeter created chat","description":"jmeter created test"} )在第一个线程中,我收到了 JSON (格式 - {"id":6054,"name":"Jmeter created chat","description":"jmeter created test"}

I want to use it in the second thread variable '6054'我想在第二个线程变量'6054'中使用它

I use BeanShell Assertion with code: ${__setProperty(("id":"(.+?)"), ${chat_id)};我使用带有代码的 BeanShell 断言: ${__setProperty(("id":"(.+?)"), ${chat_id)};

but it, of course, doesn't work, please tell me the right way..但它当然不起作用,请告诉我正确的方法..

many thanks非常感谢

  1. It won't work because your __setProperty() function call doesn't make sense at all and it's syntactically incorrect它不起作用,因为您的__setProperty() function 调用根本没有意义,而且语法不正确
  2. Since JMeter 3.1 you're supposed to use JSR223 Test Elements and Groovy language for scripting 从 JMeter 3.1 开始,您应该使用 JSR223 测试元素和 Groovy 语言进行脚本编写

So所以

  1. Remove your Beanshell Assertion删除你的 Beanshell 断言

  2. Add JSR223 PostProcessor as a child of the request which returns the above response添加JSR223 PostProcessor作为返回上述响应的请求的子项

  3. Put the following code into "Script" area:将以下代码放入“脚本”区域:

     props.put('chat_id', new groovy.json.JsonSlurper().parse(prev.getResponseData()).id as String)
  4. In 2nd Thread Group access the value using __P() function as:在第二个线程组中,使用__P() function访问值:

     ${__P(chat_id,)}

Demo:演示:

在此处输入图像描述

More information regarding what these prev and props guys mean can be found in the Top 8 JMeter Java Classes You Should Be Using with Groovy article有关这些prevprops的意思的更多信息可以在前 8 个 JMeter Java 类你应该使用 Groovy 文章中找到


PS You may find Inter-Thread Communication Plugin easier to use PS您可能会发现线程间通信插件更易于使用

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

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