Jmeter Pass Command Line Properties
Jmeter Pass Command Line Properties
Problem Statement:
As an Automation Tester,
I want to pass properties through Command line
So that I can make Jmeter plan more robust and data driven
Why It is Needed?
JMeter GUI is the place where we can create performance. Due to various reasons
(Performance, Linux Execution, CI/CD, etc), it would be best to use the command line mode
of JMeter.
There are several places where we need to change parameters in order to achieve the goal
(ex: base URL,Host, port, username, password, etc) So there are two ways,
** Either** Open Jmeter GUI and change parameters (Not Good practices)
(If feasible and OS supported, Non-Linux)
Or JMeter lets you pass parameters in command line mode. (Good practices)
jmeter -n -t your_script.jmxWhere,
-n — tells JMeter to run in non-GUI mode.
-t — specifies the path to source .jmx script to run.
In case you want to send parameters via command line, add the parameters below:
Then you need to change your JMeter file. You can receive these parameters with a built-in
function of JMeter. This function is ${__P(VariableName)} .
User property parameter under Jmeter Test Plan
Above is user defined variable and can be access throughout the jmeter test by
${VariableName} like ${host}, ${port}
Pitfall: Variables cannot be set via the command line! Cannot and — as far as I get it —
never will. But there is an alternative: properties.
Properties can be defined from the command line, and can be read from the testplan
syntax: ${__P([property],[defaultValue]} . Properties are passed using the -J option to the
jmeter start as stated earlier.
But there is a drawback with properties. Properties cannot be set easily within JMeter
itself. You have to resort to beanshell expressions to change them.
Conclusion
Properties and variables can lead to some confusion when using JMeter. In my opinion it is
meaningful to use only variables within the Test plan itself to make script maintenance free.