Combination of 'Random' and 'Counter' Functions in JMeter


Scenario:
There is a Unique Random value in input. It is there in 2 places of same input and in both places the value is same. But this value should be unique in each and every iteration

Ex: -- Input:  theinputforapplicationtesting456879hastworandomvalues456879   -- 1st iteration
          Input:  theinputforapplicationtesting367705hastworandomvalues367705  --  2nd iteration


JMeter Implementation:  (I used 2 functions for this implementation and a CSV Data set)

Step 1:
I have collected all the inputs in a file and i have replaced the random value with coma ( , ) 
theinputforapplicationtesting456879hastworandomvalues456879
theinputforapplicationtesting367705hastworandomvalues367705

After replacing random value with coma it looks as below:
  theinputforapplicationtesting,hastworandomvalues,
  theinputforapplicationtesting,hastworandomvalues,
 
For these values, I have defined the variables as v1 and v2 in CSV Data set with the coma as a delimiter

Step 2:
Function 1: _Random

Ex:
${__Random(11111,99999,)}

Add User Defined variables to JMeter (Right click on Thread Group --> Add --> Config Element --> User Defined Variables)

Use this function value in User Defined variable

Ex:
Name
Value
Description
CN
${__Random(11111,99999,)}
Random Control Number

Need to use this variable (CN) in the script

 Step 3:
Function 2: _Counter 

Ex:
${__counter(TRUE,)}

Provide this function in the script along with the variable defined in user defined variables for Random function

Ex:
${V1}${CN}${__counter(TRUE,)} ${V2}${CN}${__counter(TRUE,)}


Note:
Instead of using the function  _Counter , we can also use the Config Element ‘Counter’. Both are same.
(Right click on Thread Group --> Add --> Config Element --> Counter)

No comments:

Post a Comment