nox174
nox174

Reputation: 1

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

Upvotes: 0

Views: 66

Answers (1)

Dmitri T
Dmitri T

Reputation: 168072

  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:

enter image description here

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

Upvotes: 2

Related Questions