Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

different values for jmeter ${__UUID} in loop

Tags:

guid

jmeter

In my BSF preprocessor (language javascript), I am generating post data such as

 var totalCustomer = 2;
 var data = { "customers": [] };
 for(i=1; i<=totalCustomer; i++){

     // in all iteration getting same value for ${__UUID} 

     var customer = {
         "id": "${__UUID}"
     }
     data.customers.push(customer);
 }
 vars.putObject("data",JSON.stringify(data));

I guess it is compiled once and looked up for the value in subsequent iterations.

Is there any way I can generate different guid using ${__UUID} for each iteration?

like image 250
Sami Avatar asked Aug 20 '15 14:08

Sami


People also ask

How do I pass a value from one HTTP request to another in JMeter?

Step to implement the logic for passing the variable value to another Thread Group: Add a 'Regular Expression Extractor' post-processor as a child element of 1.1 HTTP Request (Fetcher) and fetch the value in a variable (say employeeID) Add a 'BeanShell Assertion' and write ${__setProperty(valueToPass,${employeeID})}

How do I declare a global variable in JMeter?

First we create a setup thread group and under that user defined variables. We then define the specific environment variables to use across the test plan. preprod. With the user defined variables set we then need to write them to global variables (properties).


1 Answers

  1. Replace ${__UUID} with UUID.randomUUID().toString(). Don't inline JMeter variables and functions into script, it's not very good practice and may lead to unexpected behavior (as in your case). Particular for your scenario it's better to call UUID class methods directly.
  2. Don't use BSF test elements, they're not very efficient from performance side of things. Consider using JSR223 test elements and Groovy language. See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! for explanation, benchmarks, groovy engine installation details and scripting best practices.
like image 169
Dmitri T Avatar answered Oct 09 '22 15:10

Dmitri T