JMeter – How to pass parameters into test scripts?

How to pass parameters into test scripts?

To pass parameters in JMeter scripts you can use property() function, which reads value of JMeter property.
In order to define the property so JMeter can read it, define it on the command line as follows:

 
jmeter -Jproperty_name=property_value 
 
example:
jmeter -Jhost2=www.xyz.com -Jhost1=www.yyy.net
 
These values can then be read in the test plan using:

${__property(host1)} and  ${__property(host2)}

You can also parameterize Thread Group number using Property() function. Thread Groups are slightly different from other test elements, because their settings have to be determined before the test starts. This means that you cannot use variables defined in a User Defined Variables.
Suppose you want to be able to vary the number of threads in a test plan. Choose a suitable property name, say group1.threads. Replace the thread count in the GUI with the following function call:
 ${__property(group1.threads)} 
 
Then, when starting JMeter, define the property on the command line:
 jmeter -Jgroup1.threads=12345 
 
 
It can be useful to put default settings into the jmeter property file, so you only need to supply differences on the command line.
 

 

# defaults in jmeter.properties
group1.threads=10
group1.loops=100
group1.rampup=10

2 Comments

    • You can use User defined vairables in TG but values like number of threads, rampup time, default urls need to be provided before test starts. Also, if you are using command line to execute your script, changing Thread number through command line is easier.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.