Search code examples
javaperformance-testingjmeter-5.0

Sending dynamic values in soap messages in JMeter


Can someone let me know how to send dynamic values in soap messages during the load test in JMeter? I tried BeanShell Preprocessor and used the code given below :

import java.util.Random;

randomstring ="";

int number = 0; for (int i=0; i <= 1; i++) { randomstring = number.toString(); print(randomstring);
vars.put("randomstring",randomstring); number++; }

It's sending the same value again and again.I want to send different value every time.


Solution

  • It happens because you're overwriting the randomstring variable on each iteration so only last occurrence is getting stored.

    Also, since JMeter 3.1 you're supposed to be using JSR223 Test Elements and Groovy language for scripting where possible.

    And finally, you don't even need to go for scripting, if all you need is to generate a random number - it is easily achievable via JMeter's built-in __Random() function which can be placed directly in the SOAP message body:

    ${__Random(1,2147483647,)}
    

    Demo:

    enter image description here

    More information on JMeter Functions concept: Apache JMeter Functions - An Introduction