jmeter pass command line variables into a jmx
Solution 1
All you need to do is start your JMeter from the command line (or shell) with the -J option. For example :
-JTestIP=10.0.0.1
And in your script, to get the value, just use function _P:
Example:
${__P(TestIP)}
That should do it.
Note you should put a default value in case you run the script without passing that JMeter property like:
${__P(TestIP,1.1.1.1)}
Solution 2
Take a look at this link http://mkbansal.wordpress.com/2012/08/01/jmeter-command-line-script-execution-with-arguments/. Also I would try to specify default value, like ${__P(testingFromCommandLineIP,defaultIP)}
where testingFromCommandLineIP
-- argument you specify when running test plan from command line, defaultIP
-- default value
Solution 3
- Open the Jmeter file (jmx) in Jmeter GUI and add parameters as this screenshot:
-
Now, run command with this parameters, for example:
jmeter -t TestPlan.jmx -Jthreads=10 -Jcount=50 -Jrumpup=5
Solution 4
You have two options to send parameters to jmeter.
First: Sets a system property value.
-Dproperty=value
If value is a string that contains spaces, then you must enclose the string in double quotation marks.
Example:
java -Dmydir="some string" -jar ApacheJmeter.jar -n -t PerformanceTest.jmx
Reading parameters in jsr223 beanshell:
log.info("mydir:" + System.getProperty("mydir"));
Reading parameters in request sampler with Bean Shell function:
${__BeanShell(System.getProperty("mydir"))}
Second: Defines a local JMeter property
-J[prop_name]=[value]
Example:
jmeter -n -t PerformanceTest.jmx -Jmyparamter=4 -Jduration=300
Reading properties in request sampler with Bean Shell function:
${__P(duration)}
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I'm trying to automate some perf testing. I'd to pass server locations into a generic jmx from a Jenkins job. I'd like to be able to do something like:
jmeter -n -t foo.jmx -JtestingIP=IP
and have foo.jmx pick up
testingIP
.What is the proper way to do this? When I run that jmeter command, it says that the variable has been stored, but inserting either
${testingIP}
or${\_\_P(testingIP,)}
into the jmx results in${testingIP}
or${\_\_P(testingIP,)}
to be interpreted as just a string.What am I doing wrong/not doing at all? Is this even possible?
-
Bruno Bieri over 7 yearsWorks in jmeter 3.0. Thank you!
-
Gunjan Shah about 3 yearsIt worked for me. I am using Jmeter Java 1.0