简体   繁体   中英

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"} )

I want to use it in the second thread variable '6054'

I use BeanShell Assertion with code: ${__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
  2. Since JMeter 3.1 you're supposed to use JSR223 Test Elements and Groovy language for scripting

So

  1. Remove your Beanshell Assertion

  2. Add JSR223 PostProcessor as a child of the request which returns the above response

  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(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


PS You may find Inter-Thread Communication Plugin easier to use

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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