0
votes

I am trying to run some tests, using jmeters random beanshell post processor, but somehow, randomly it fails to create the numbers and instead posts "variable=${variable_value}" directly in the url.

Here is the sample beanshell post processor code:

import java.util.*;

r = new Random();
b = new Random();
t = new Random();

random_param1 = r.nextInt(415000);
random_param2 = b.nextInt(200);
random_param3 = t.nextInt(25);

vars.put("random_param1",random_param1.toString());
vars.put("random_param2",random_param2.toString());
vars.put("random_param3",random_param3.toString());

And here how I set those for the url:

enter image description here

And the simple test results looks like this:

enter image description here

And this is a failed test request data:

POST test_url

POST data:
param1=%24%7Brandom_param1%7D&param2=%24%7Brandom_param2%7D&param3=%24%7Brandom_param3%7D

While the successful ones are like:

POST test_url

POST data:
param1=287341&param2=107&param3=20

Any ideas why random generation fails "randomly" like this? Should I use a specific sampler?

EDIT: enter image description hereenter image description here

1
show you test plan zooming on beanshell position, thxUBIK LOAD PACK
@PMDUBIK-INGENIERIE you mean you wanna see the whole screen with the beanshell?denizdurmus
By the way, the problem is only happening for the first 20-25 requests, then as the tests are going on, it never repeatsdenizdurmus
is using beanshell processor mandatory for you?. I think if you need it just for random no. generation you can use random variable. will that do for you?Nachiket Kate
I think that is some kind of code/thread synchronization issue. If you want, I can provide the solution with random no. generator, which I have used and tested many times and I hope you will not face such issue there.let me know if you need it.Nachiket Kate

1 Answers

-1
votes

Your beanshell code contains an error in the screenshot (so in test plan), you don't set in vars:

  • random_param2