Use the below Java script to generate the GUID in JMeter:
MyGUIDScript=var chars = '0123456789abcdef'.split(''); var uuid = [], rnd = Math.random, r; uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[14] = '4'; for (var i = 0; i < 36; i++) { if (!uuid[i]) {r = 0 | rnd()*16; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf]; } }; uuid.join('');
then use this to get the GUID
${__javaScript(${MyGUIDScript},GUID)}
MyGUIDScript=var chars = '0123456789abcdef'.split(''); var uuid = [], rnd = Math.random, r; uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[14] = '4'; for (var i = 0; i < 36; i++) { if (!uuid[i]) {r = 0 | rnd()*16; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf]; } }; uuid.join('');
then use this to get the GUID
${__javaScript(${MyGUIDScript},GUID)}
can this be explained more...how to use it and wher to use it jmeter...tahnx ..any help is appeciated....
ReplyDeleteCreate the following test plan.
DeleteTest Plan
--Thread Group
--User Defined Variable1
--User Defined Variable2
--Debug Sampler
--View Results Tree
In the User Defined Variable1 enter
Name: MyGUIDScript
Value: var chars = '0123456789abcdef'.split(''); var uuid = [], rnd = Math.random, r; uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; uuid[14] = '4'; for (var i = 0; i < 36; i++) { if (!uuid[i]) {r = 0 | rnd()*16; uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf]; } }; uuid.join('');
In the User Defined Variable2 enter
Name: GUID
Value: ${__javaScript(${MyGUIDScript},GUID)}
And the run the test, you will find the GUID value in debug sampler.
Use this "${__javaScript(${MyGUIDScript},GUID)}" to generate GUID
DeleteGreat script, many thanks. Quick question, what is the reason behind the following code in the function?
Deleteuuid[14] = '4';
I believe the 4 in that position in the string is to account for the UUID/GUID being "version 4" - see here: http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29
DeleteThank you very much :-) that saved me some time, works like a charm!
ReplyDeleteWhen I use this in order to generate a random GUID to be inserted into the path of my request, it only gets generated once per test run so all requests use the same GUID. I assume this is because the variable is calculated only once, then used over and over. Is there any way to adapt this to generate once per request or if that would be too costly, to generate a list of them, then use the list?
ReplyDeleteJust wanted to say thanks for this. very useful!
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteHey, incase anyone is still wondering about Big B's question, if you use a user parameter instead of 2nd user defined variable it will change every iteration (if you check the relevant option). Many thanks for this!
ReplyDeleteThanks that works like a charm userParameter helps generate GUID every thread
ReplyDeleteYou just need to reference ${UUID()}
ReplyDelete...as detailed here:
ReplyDeletehttp://jmeter.apache.org/usermanual/functions.html#__UUID
Ok, once more with feeling. Two underscores must precede the function name. Hoping this renders correctly: ${__UUID()}
ReplyDeleteHOW TO PASS UUID FOR EACH SAMPLES AND ALSO HOW WE CAN PASS IN JMS SUBSCRIBER
ReplyDelete