One area where JMeter certainly excels is in its seeming infinite extensibility, including a dizzying array of plugins and multiple scripting options on top of an already versatile test designer. Along these lines, here we will be discussing how to set properties as command line options through the Redline13 user interface. Ultimately, these will be passed to load agents running JMeter, but the hard parts will be managed by the RedLine13 service.
As a standalone tool, JMeter extends the ability to import a collection of name-value pairs independent of the actual test plan file. This can be particularly useful when we already have a developed test plan, but perhaps wish to change host targets or request options without rewriting the core test architecture each time. Similar to our hypothetical example described below, you may find it necessary to change HTTP request parameters from one test set to the next. Rather than modifying and uploading a new test plan for each run, we can reuse a previous test plan provided that it is somehow configurable. JMeter properties set as command line options are an excellent way to achieve this, simplifying test plan administration and facilitating reuse.
Among the key benefits of using RedLine13 is the ability to abstract away the burdens of administering JMeter execution on distributed load agents, synchronizing their activity, and monitoring for results. This same level of abstraction forgoes the versatility of the command line. However, RedLine13 has provided a convenient way to specify these options when creating new tests. Due to the very specific syntax (a JMeter requirement) we have assembled some brief instructions on how to accomplish this.
Part 1. Specifying custom properties
As specified in the documentation, JMeter options when specified from the command line take the following form:
-J[prop_name]=[value]
|
Such is, that if we wanted to declare a property named “email” with a value of “johndoe@redline13.com”, we would specify this in the following form:
-Jemail=johndoe@redline13.com
|
Furthermore, to illustrate specifying multiple options together, we can declare:
-Jemail=johndoe@redline13.com -Jcompany=RedLine13
|
Note that each key-value pair is preceded by the “-J” prefix without any separation between the property name. Also note that each name-value pair is delimited by a space. You may continue this convention to specify as many options as necessary for your unique test scenario. When using the RedLine13 user interface to start a load test, we have conveniently provided a special input area under “Advanced JMeter Test Options” to specify the entire JMeter option string:
Subsequently on completed load tests, you may view which JMeter options have been set under the “Test Opts” heading which is listed under “Details” on the results page.
Part 2. Accessing custom properties within JMeter test plans
Now that we have covered how to set custom properties, we will need to reference those properties in order to use them within our actual JMeter test plan. Just as with specifying these properties at the command line, there is a specialized syntax for reading them into JMeter.
As an introduction, there is a built-in JMeter function “__P()” which is documented here. By referring to this function in your test plan, you can directly access predefined properties that have been specified at the command line via the manner outlined above. Typically this call is wrapped in ${…} so that it can be referenced from fields which normally contain literals. (In another post, we also outline accessing properties for a different purpose.) For example, the following value will pull a property declared as “email” into a request string of an HTTP Request sampler:
http://www.domain.com/page?account=${__P(email)}
From within JMeter this can be set up as follows:
The end result is that you are now able to construct generic test plans, and easily modify them from the RedLine13 user interface. This makes it possible to tailor them to specific use cases without the need to change the test plan itself. Of course, these are simple examples designed to illustrate the basic concepts. However, by building upon this using more complex test elements and scripting, the possibilities are practically endless. Try this for yourself today with a free RedLine13 trial account.