Getting your Trinity Audio player ready...
JMeter warning for running test in GUI

JMeter users will be definitely familiar with this message.

When we want an optimal test result, we don’t have any other choice than to go with CLI mode. Load testing the application means we will be constantly changing the load configuration in the script and running the test.

So every time we want to configure the load for the test, we will be opening the JMeter script, updating the configuration, saving the script, and running it in the terminal.

This process is time-consuming and may lead to some errors while saving the script. But we don’t have to do it anymore. We can configure the load using JMeter properties instead of updating the script each time.

What is Property Function in JMeter?

Before diving into how to add properties from outside the script, let us see how to refer to the values of the properties inside the script.

__P() is a simplified property function used to return the value of a JMeter property, we will use this in the places where we want to refer to the JMeter properties that we are going to create.

Ex:- ${__P(thread)} will get the value of the property named “thread”

Normal JMeter script will look like the following.

Default JMeter script without parameterisation for load configuration

After adding the property function, the script will look like the following.

JMeter script with parameterisation for load configuration

Now let us see how to set values for the properties referenced in the test script using the command line and property file.

Pass Properties from Command Line

From the  CLI using the -J flag, we can create the properties which will be referenced in the script. Now when we run the test script using the following command.

we will get the following result where 100 user requests have been sent within 10 secs for 2 different endpoints.

Test result for load configuration using command line arguments

Pass Properties from File

JMeter uses two properties file user.properties and jmeter.properties for configuring JMeter settings. We can add our properties file for load configuration. Let’s create a file that will have the following properties.

Now, let’s run our script by passing the name of the property file that we created, using the -q flag.

we will get the following result where 200 user requests have been sent within 10 secs for 2 different endpoints.

Test result for load configuration using property file

I just want to debug JMeter Script!!

Before running the test, we will want to make sure the test plan that we created works fine.

We can change the property function to ${__P(thread, 1)} which accepts the default value. JMeter will use the default value assigned when it can’t find any value for the referenced property.

This will help us debug our script without the need of passing properties referenced in the script.

Jmeter Script updated with property function accepting default value

Now we can just run the script without passing any properties and make sure our test plan is perfect.

From the following result, we can see JMeter has used the default value and sent 1 request to 2 different endpoints only once within 1 sec.

Test result for default load config

Conclusion

Using JMeter properties we can save a lot of time in configuring load but it’s not just limited to load configuration, we can use it to parameterise the following fields.

  1. Server name
  2. CSV data file path

References

https://octoperf.com/blog/2019/01/14/flexible-test-plans/#why-configurable-tests

https://jmeter.apache.org/usermanual/

For more blogs, please refer to Rently Blog.

Leave a Reply

Login with