0% found this document useful (0 votes)
83 views3 pages

Jmeter Pass Command Line Properties

This document discusses best practices for passing command line properties in JMeter for data-driven testing. It recommends defining variables in the JMeter test plan that reference properties passed from the command line using the -J option. For example, running "jmeter -n -t test.jmx -Jhost=test.com -Jport=8080" and referencing them in the test plan as ${__P(host)} and ${__P(port)}. This allows variables to be initialized with properties and reused throughout the test plan. The document also suggests defining all command line properties in an external properties file to simplify passing many parameters.

Uploaded by

Manuel Vega
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
83 views3 pages

Jmeter Pass Command Line Properties

This document discusses best practices for passing command line properties in JMeter for data-driven testing. It recommends defining variables in the JMeter test plan that reference properties passed from the command line using the -J option. For example, running "jmeter -n -t test.jmx -Jhost=test.com -Jport=8080" and referencing them in the test plan as ${__P(host)} and ${__P(port)}. This allows variables to be initialized with properties and reused throughout the test plan. The document also suggests defining all command line properties in an external properties file to simplify passing many parameters.

Uploaded by

Manuel Vega
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

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)

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.

You might also like