Variables in httprequest post body

user2237424 picture user2237424 · Apr 2, 2013 · Viewed 59.4k times · Source

I'm trying to generate a jmeter script where a unique folder is created each time the script is run - adding a variable of some sort to the folder name, such as a username+timestamp, should be enough to guarantee uniqueness. However, jmeter is not resolving the variable to its value - although it is when the variable is read out of a csv file (which isn't suitable).

Basically, I'm editing the PostBody in the http request, as follows:

 {"alf_destination":"workspace://SpacesStore/90368635-78a1-4dc5-be9e-33458f09c3f6","prop_cm_name":"Test
 Folder - ${variable}","prop_cm_title":"Test
 Folder","prop_cm_description":"Test Folder"}

where variable is basically any variable I've tried so far (such as a random string, timestamp, etc.)

Can anyone suggest how to get the variable resolved?

Answer

z2z picture z2z · Sep 5, 2013

You can use jmeter (since 2.9 version) uuid feature -> http://jmeter.apache.org/usermanual/functions.html#__UUID

${__UUID}

and

1) If you want just 1 value for the whole test, add a "User Defined Variables" Config Element to your test. This will be evaluated when you load the test script the first time.

2) If you want to have the value change for every thread execution, but stay the same during each thread instance: under your 'Thread Group', add a 'Pre Processors -> User Parameters' to your thread group - and add the variable there.

Also, if you want the value to change each time the thread starts over (each 'iteration' of the script within the thread group), you can check the "Update Once Per Iteration" box on the User Parameters - and it will get a new value each time it starts the thread over at the beginning of th test script (within that thread group).

http://mail-archives.apache.org/mod_mbox/jmeter-user/201208.mbox/%[email protected]%3E