1
votes

First, let me preface this question that I've only been using JMeter for 36 hours.

I've been able to successfully create a thread that performs a POST (json body) to generate a new record.

{  
   "id":1257697771,
   "displayName":"TERM2",
   "functionName":"f_1257697771",
   "displayableSourceExpression":"TRUE",
   "typeId":200,
   "groupId":300,
   "clobObjId":1257697772,
   "typeCode":5,
   ..........
}

I need to take the new record's ID (1257697771) value returned in order to perform updates, get by ID, delete, etc. on this record in other threads.

After much reading, I've created a Regular Expression Extractor where:

  • Apply to: Main Sample Only
  • Field to Check: Body as Document
  • Reference Name: newRecord
  • Regular Expression: "id":(.+?)\,"displayName"
  • Template: $1$
  • Match No: 1
  • Default Value: NONE

At this point, I'm not sure if my Regular Expression is formatted correctly where (.+?) is valid.

Also, I'm confused if I can either just specify the new reference (newRecord) in another thread's HTTP request's Parameters or use a BeanShell Post-Processor, or a Response Assertion, etc....

There a lot of answers for the same function of "Passing". Not being a programmer, I've tried to follow the discussion "how to extract json response data in jmeter using regular expression extractor?", but I'm still not clear.

Any insight is appreciated. Thanks.

3
Regexp is better to be: "id":(\d+?), newRecord you can use in every another sampers and beanshells using ${newRecord}. In beanshel is also you can get value using String s = vars.get("newRecord");v0devil

3 Answers

4
votes

JMeter Variables are local to Thread Group, you need to convert your variable to JMeter Property.

Use:

  1. __setProperty() function in the Thread Group where you define your newRecord variable like:

     ${__setProperty(newRecord,${newRecord},)}
    
  2. __P() function to access property value like:

    ${__P(newRecord,)}
    

Passing variable between thread groups

See Knit One Pearl Two: How to Use Variables in Different Thread Groups article for more detailed explanation.

Also be aware of the Function Helper Dialog as it looks like JMeter functions syntax was developed by aliens.

3
votes

To pass a value between threads you need to use the jmeter property function.

In a jsr223 postprocessor using groovy the code to get the value is as follows:

 def userProperty = props.get('propertyToGet')
vars.put('userProperty', String.valueOf(userProperty))

You would then access the variable in your thread using:

${userProperty}

Or you can use shorthand directly:

${__P('propertyToGet')}

Variables in jmeter are thread specific.

1
votes

Thanks everyone. I was able to resolve it with your help!

In the first thread:

  • set the Reg Expression Extractor Regular Expression = "id":(.+?)\,"displayName"

  • added a Bean Assertion where Parameters = ${__setProperty(newRecord,${newRecord},)}

In the second thread:

  • appended the Path url with ${__P(newRecord,)}

Executing the first thread (POST) resulted an new record with a unique ID. (1257698108)

Executing the 2nd thread (GET) shows

GET http://server/.../.../.../.../1257698108

And returns the exact data generated in the first thread.

Thanks everyone for your help!