Jmeter | Pass Command line properties

Priyank Shah
3 min readJan 24, 2020

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)
User defined variable under Jmeter

How to Pass an Argument via the Command Line

A basic command line parameter is,

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:

jmeter -n -t your_script.jmx -Jhost=myapp.Test.com -Jport=8892

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

But, Is this the optimized / feasible way to do it?

  • In JMeter, there is a difference between variables and properties. This difference often leads to confusions. Often variables are defined within the testplan.
User defined variable under Jmeter
  • 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.

So, What is the Solution then?

  • Only use variables within your Test plan.
  • Define variables on the Test plan and allow there variables to be initialized with a property. EX: host = ${__P(host)}
  • Always use the variable within the Test plan
User defined variable mapped to properties

Now we can run test through commend line,

jmeter -n -t your_script.jmx -Jhost=myapp.Test.com -Jport=8892 -Jprotocol=http -JsearchStartDate=20/05/2019 21:20:00 -JsearchEndDate=21/05/2019 21:20:00

Well, Can it be further optimized?

There is no limit for optimization. Currently, We can see one issue with passing parameter from command line. It is very difficult if we have more command line parameters. There MUST be some way where we can pass just property file to the command line and all command line parameters are defined under property file.

jmeter -n -t your_script.jmx -p <Name of Property file>.properties

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.

--

--

Priyank Shah

Agile Product Leader | Delivery Manager | Design Thinker (PRINCE2, CSPO™, CSM™, SFC™, ISTQB)