I am trying to use beanshell preprocessor for parameterization in JMeter script.My JMeter script structure is as mentioned below. Test plan->Thread group->Transaction Controller->Requests.I want to know which procedure I should follow to dynamically pass values to the request.
Description with screenshot and an example will be more helpful.
Thanks in advance.
Try out the following test structure:
Beanshell Pre Processor as a child of HTTP Request with the following code:
int min = Integer.parseInt(bsh.args[0]); // get first parameter
int max = Integer.parseInt(bsh.args[1]); // get second parameter
int random = min + (int) (Math.random() * ((max - min) + 1)); // calculate random number within parameters range
vars.put("RANDOM_NUMBER", String.valueOf(random)); // save result into RANDOM_NUMBER variable
and 100 300
in "Parameters: section
So in Beanshell Pre Processor we define RANDOM_NUMBER
variable value which we refer in HTTP Request Sampler. Pre Processor is being executed before request so variable gets populated. If you add View Results Tree listener you'll see that requests contain randomly generated numbers in 100-300 range
So you need to add Beanshell Pre Processor as a child of request you're going to parametrize.
See How to use BeanShell: JMeter's favorite built-in component guide for more information on Beanshell scripting and small cookbook.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With