'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
Solution 1:[1]
- It won't work because your __setProperty() function call doesn't make sense at all and it's syntactically incorrect
- Since JMeter 3.1 you're supposed to use JSR223 Test Elements and Groovy language for scripting
So
Remove your Beanshell Assertion
Add JSR223 PostProcessor as a child of the request which returns the above response
Put the following code into "Script" area:
props.put('chat_id', new groovy.json.JsonSlurper().parse(prev.getResponseData()).id as String)
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
P.S. You may find Inter-Thread Communication Plugin easier to use
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitri T |