Friday, May 27, 2011

GUID generation using JMeter

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)}