jmeter pass command line variables into a jmx
Asked Answered
A

4

44

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?

Amusing answered 6/11, 2013 at 22:15 Comment(0)
P
81

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)}

Pervade answered 7/11, 2013 at 7:49 Comment(3)
Works in jmeter 3.0. Thank you!Kennethkennett
It worked for me. I am using Jmeter Java 1.0Tosspot
It requires to add a Config Element in JMeter for User Defined Variables to include custom variables/properties defined by the programmer.Batchelor
S
14
  1. Open the Jmeter file (jmx) in Jmeter GUI and add parameters as in this screenshot:

enter image description here Click on Save button.

  1. Now, run the command with these parameters, for example:

     jmeter -t TestPlan.jmx -Jthreads=10 -Jcount=50 -Jrumpup=5 
    
Spaetzle answered 15/1, 2019 at 10:17 Comment(0)
L
11

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

Loydloydie answered 7/11, 2013 at 7:45 Comment(0)
I
5

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)}
Iamb answered 26/3, 2020 at 13:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.