Although I’m not that new to JMeter, it’s a pretty versatile piece of software, and it’s not uncommon to find efficient new ways to structure your tests. New features and enhancements are also added to it regularly which makes it even more likely that you’ll find better tools to enhance your load tests.
Targeting Multiple Environments in One HttpRequest Sampler
If you run load tests against a dedicated environment, then this tip would not be useful, otherwise, it’s a handy way of targeting different environments within one HttpRequest sampler, with environment specific data etc.
To make it work, you add a variable to your tests that will hold the environment data. In my tests, I use the environment to control the following two things:
- The endpoint url
- The csv filename for loading test data
You can use User Defined Variables almost anywhere once you declare them. You can also combine variables together, so in my example, I’m combining the environment variable, with substring for the api url, common to all my endpoints and resolving it using the in-built “__V” function.
Cycling through a list of User Defined Variables using a number suffix
This strategy comes in handy when you have a relatively small, finite set of values that you would like to pass to your endpoint randomly. For instance, a list of sizes for an e-commerce website that sells t-shirts, and a search page that takes a size query parameter, with values Extra Small (XS), Small (S), Medium (M), Large(L) and Extra Large (XL). You can create 5 variables as follows:
- size_1
- size_2
- …
- size_5
Then, using a combination of the “__V” variable and the “__Random” variable, you can add an endpoint that looks like the following:
Load Varying Query Params for an endpoint
It’s easy enough to just tack on query string parameters to the end of a url, and pull in variables, or data from a CSV file to populate their values. The drawback of doing this is you won’t be able to optionally omit or add query string parameters. So if you go with the strategy directly below:
You won’t be able to use the same url to test load times for a url that omits the page or limit parameter.
The way around this is to load a string containing all the query parameters from a CSV file. So your CSV file would look like this:
As you can see, you can adjust which query string parameters show up in your test-url by manipulating the strings in the CSV.
The above is just the fun discoveries I’ve made recently in using JMeter. One additional freebie I would throw in there, is a tip you’ve probably read in a lot of other places — it’s, don’t use the GUI to execute your test. It’s
jmeter -n -t [jmx file] -l [results file] -e -o [Path to web report folder]
Enjoy!