0
votes

So i have some tests in Jmeter which i'm running using this command:

java -jar .\bin\ApacheJMeter.jar -n -t .\bin\Example-Test-Plan.jmx 

in this test i have variable 'users' which i want to change in runtime using beanshell like this:

java -jar .\lib\bshclient.jar localhost 9000 .\bsh\update_parameter.bsh 200.

This is my update_parameter.bsh file:

setprop("users", args[0]);

When i run above things i get this:

Connecting to BSH server on localhost:9000
Reading responses from server ...
BeanShell 2.0b6 - by Pat Niemeyer ([email protected])
bsh % // Error: EvalError: Command not found: setprop( java.lang.String, java.lang.String ) : at Line: 2 : in file: <unknown file> : setprop ( "users" , args [ 0 ] )

bsh % ... disconnected from server.

When i run same tests using GUI the parameter updates just fine... Any ideas why this is happening?

1

1 Answers

0
votes

This setprop function is defined in startup.bsh file and it looks like:

setprop(p,v){// set a JMeter property
print("Setting property '"+p+"' to '"+v+"'.");
JMeterUtils.getJMeterProperties().setProperty(p, v);
}

So make sure to define beanshell.server.file property pointing to this startup.bsh file and you should be able to use this or any other shorthand declared there.

enter image description here

In any case you can amend your code to something like:

org.apache.jmeter.util.JMeterUtils.setProperty("users",args[0]);

and it will have the same effect.

More information: