Jan. 29th, 2014

Apache JMeter Properties Customization Guide

For your intellectual dining pleasure, on today's JMeter menu we have:

 

  • Property Types 2

  • System Properties 2

  • Example use case: changing “file.encoding” property 3

  • JMeter Properties 4

  • Example use case: changing “CookieManager.save.cookies” property 5

 

JMeter Property Types

 

Let's start with some appetizers. There are 2 types of properties which are in use by Apache JMeter which we recommend starting with: 

 

  • System Properties
  • JMeter Properties

 

System Properties

 

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

 

Properties class documentation is available at Oracle website.

 

You can see a full set of predefined properties by using for example 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

 

See output in STDOUT

 

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

 

Sample use case: changing “file.encoding” property

 

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

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

- Option 2 – use 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 “file.encoding” property value in Debug Sampler “Response Data”

JMeter “file.encoding” property value in Debug Sampler “Response Data”

 

- 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 stuff after /?q= in “Request” tab of View Results Tree listener

 

“Request” tab of View Results Tree listener in JMeter
 
2.Change “file.encoding” property

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

 

Change “file.encoding” property

 

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

 

Add “file.encoding=UTF-8”

 

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 

 

The Main Course: JMeter Properties

 

JMeter Properties are like System Properties and 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 JMeter properties 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.

 

System Properties PLUS JMeter properties
 
3. By using __P or __property functions. 

 

Almost any area of 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. 

 

It's a good place to set / override properties is “user.properties” file. 

 

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

 

And now for dessert. Cookies anyone?

 

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:

 

“Response Data” tab of Debug Sampler

 

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

 

“HTTP Request” -> Sample Result -> Response Headers

 

Let’s add CookieManager.save.cookies=true somewhere in “user.properties” file

 

CookieManager.save.cookies=true somewhere in “user.properties”

 

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. 

 

cookies stored as JMeter variables
 

 

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

 

1. Command-line argument –Jpropertyname=propertyvalue

 

Jpropertyname=propertyvalue
 
 
2. Add “propertyname=propertyvalue” anywhere to the “user.properties” file. 

 

BlazeMeter supports all above properties overriding mechanisms and as usual simplifies setting custom properties process to a matter of seconds. In addition the Real Time JMeter Properties Control feature during test execution so you'll be able 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.

 

BlazeMeter's JMeter Properties

 

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

 

Expand “Advanced Test Properties” and get full control on BlazeMeter

 

So in total we have 5 properties set:

 

  • 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)

 

(ignore “ERROR” as its intentional usage of error logging

 

How is that for a 3 course JMeter infusion to the senses?

 

Want to learn more about JMeter?

 

Check out our free Webinar "How to Make JMeter Load Tests Highly Scalable and More Collaborative with BlazeMeter".

 

Interested in writing for our Blog? Send us a pitch!