January 29, 2020

Apache JMeter Properties Customization Guide

Open Source Automation

Ready to customize your JMeter properties? This guide will go over some of the most popular JMeter property customizations. 

Feel free to read along or skip to the section that interests you most.

Back to top

Types of JMeter Properties

There are 2 types of properties that are in use by Apache JMeter which we recommend starting with: 

System Properties

JMeter Properties

Back to top

System Properties

System properties are commonly used by any Java application. Since Apache JMeter is a purely Java application, it inherits all default properties and has the capabilities to access and override them. 

The properties class documentation is available on the Oracle website.

You can see a full set of predefined properties by using the BeanShell Sampler. 

  1. Add a Thread Group to Test Plan.
  2. Add a BeanShell Sampler to Thread Group as a child.
  3. Add the following code to BeanShell Sampler in “Script” area:
    • System.getProperties().list(System.out);
  4. See output in STDOUT for details.
Beanshell Graph 1

There is a file in %JMETER_HOME%\bin folder called “system.properties” which is designed for overriding system properties. 

Sample Use Case: Changing the “file.encoding” Property

1. Obtain the default value of “file.encoding” property

- Option 1 – use the BeanShell Sampler and  System.getProperty(“file.encoding”)get “file.encoding” property value from STDOUT.

- Option 2 – use the Debug Sampler and View Results Tree 

  • Add a Thread Group to Test Plan.
  • Add Debug Sampler to Thread Group.
  • Set “System properties” to “true”, others to “false.”
  • Add View Results Tree listener to Test Plan.
  • Run the test.
  • Note the “file.encoding” property value in the Debug Sampler “Response Data.”
Apache Graph 1

- Option 3 – use JMeter __P or __property function.

  • Add a Thread Group to Test Plan.
  • Add a HTTP Request Sampler with the following:
    • Server name - google.com.
    • Path - /
    • Parameters: Name:  q, Value: ${__P(file.encoding,)} 
  • Add View Results Tree Listener.
  • Run the test.
  • Note the characters after /?q= in “Request” tab of View Results Tree listener.
Apache Image 3
 
2.Change “file.encoding” property
 

- Option 1 – Command line argument –Dpropertyname=propertyvalue orinvoke your JMeter startup script with “-Dfile.encoding=UTF8”  parameter

Apache Image 4

- Option 2 – Add “file.encoding=UTF-8” (without quotes) anywhere to “system.properties” file

Apache Image 5

Start or Restart JMeter and check “file.encoding” property with any of methods listed above. 

Both options are available on BlazeMeter: 

- Command line way – see Advanced Test Properties -> Additional JMeter Console Command Line Arguments and Additional JMeterEngine Command Line Arguments

- system.properties way – “system.properties” override file can be uploaded via Files interface 

Back to top

JMeter Properties

JMeter Properties are like System Properties and are widely used in advanced JMeter scripting. They are used for passing data between thread groups or storing something more permanent where JMeter Variables cannot be used.

Pre-defined properties live in the “jmeter.properties” file; it provides rather good reference on what they’re for. 

The default list can be viewed in several ways: 

1. By reading “jmeter.properties” file using any text viewer tool

2. Listing via BeanShells script. Beanshell sampler, post- and pre- processors provide “props” object which can be used for getting/setting JMeter properties. The script code is as follows:

  • props.list(System.out);

Basically, it returns all the System Properties PLUS JMeter properties remote_hosts, jmeter.version, etc. are JMeter Properties.

Apache Image 6
 
3. By using __P or __property functions. 
 

Almost any area of a JMeter application can be controlled by JMeter Properties starting from look and feel, timestamps, log levels, output file formats, and ending with low-level parameters of underlying libraries like Http Client timeouts, bind addresses, etc. used for different protocols connections. 

A good place to set or override these properties is the “user.properties” file. 

The values, specified in the “user.properties” file override the corresponding values from the “jmeter.properties” file. 

Sample Use Case: Changing “CookieManager.save.cookies” Property

Sometimes in the case of cookie-based authentication, it’s necessary to store HTTP cookies, which are coming from server under test in Set-Cookie header. This is to ensure that each thread is considered to be a unique user from server perspective.

By default the CookieManager.save.cookies property is set to “false” – this option won’t allow to save cookies for later usage. This example will demonstrate capability of overriding default behavior. 

Starting with next test plan structure: 

  • HTTP Cookie Manager (all defaults).
  • HTTP Request (all defaults, Server Name or IP – google.com).
  • Debug Sampler (JMeter Variables – true, others – false).
  • View Results Tree.

Now, execute the script and look into “Response Data” tab of Debug Sampler:

Apache Image 7

As we can see, no cookies were stored; however, they were set. Looking into “HTTP Request” -> Sample Result -> Response Headers – the following is present:

Apache Image 7
Let us add CookieManager.save.cookies=true somewhere in the “user.properties” file.
Apache Image 8
 

Restart JMeter and re-run the script. 

Now the cookies will be stored as a JMeter variable and can be iterated by For Each controller, stored to properties, etc. 

Apache Image 9
 

Assuming all above, there are two ways of overriding JMeter Properties:

1. Command-line argument –Jpropertyname=propertyvalue.

Apache Image 10
 
2. Add “propertyname=propertyvalue” anywhere to the “user.properties” file. 

 

BlazeMeter supports all the above property overriding mechanisms and simplifies the setting custom properties process to a matter of seconds. In addition, the Real Time JMeter Properties Control feature during test execution enables you to play with any property and immediately see the impact in Load Report section.

For “user.properties” and “system.properties” files overrides – just drop them to the same place where .jmx and .jar files usually go.

Apache Image 11

Don't want files or need to set more properties which aren't in files? Expand “Advanced Test Properties” and get full control

Apache Image 12
Back to top

Bottom Line

Throughout this guide, we set up a total of five JMeter properties:

  • user.properties file with one property called “this.is.from.user.properties” and having value of “property_from_user_properties”
  • system.properties file with one property called “this.is.from.system.properties” and having value of “from_system_properties”
  • One property set via “-J” command line argument via “Console Command Line” section - “this.is.property.from.Blazemeter.console.section” having value of “property_from_Blazemeter_console”
  • Two properties set via Blazemeter GUI:
    • “this.is.property.set.via.Blazemeter.section.1” with value of “property_from_Blazemeter_number_one”
    • “this.is.property.set.via.Blazemeter.section.2” with value of “property_from_Blazemeter_number_two”

To visualize the properties, we'll use a Beanshell Sampler with the following code:

Enumeration propertyNames = props.propertyNames();

while (propertyNames.hasMoreElements()) {

    String currentprop = (String) propertyNames.nextElement();

    if (currentprop.startsWith("this")) {

        log.error(currentprop + "=" + props.getProperty(currentprop));

    }

}

which will print all the properties starting with “this” names and values to JMeter log.

See below for output (ignore “ERROR” as its intentional usage of error logging to bring some color)

Apache Image 13

Want to learn more about JMeter? Check out BlazeMeter University.

START TESTING NOW

Back to top