Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variables in httprequest post body

Tags:

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?

like image 882
user2237424 Avatar asked Apr 02 '13 18:04

user2237424


People also ask

How do you pass variables in request body in Jmeter?

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.

Can we send parameters in POST request?

In a POST request, the parameters are sent as a body of the request, after the headers. To do a POST with HttpURLConnection, you need to write the parameters to the connection after you have opened the connection.

Can HTTP POST have query parameters?

POST should not have query param. You can implement the service to honor the query param, but this is against REST spec.


1 Answers

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

like image 156
z2z Avatar answered Oct 20 '22 02:10

z2z