Data randomization — Postman vs. jMeter

mati-qa
5 min readSep 5, 2023

--

Intro

We already discussed basic use cases regarding Postman and jMeter. I hope, we can now easily start using both tools and my examples are pretty clear. Let’s now assume, we would like to randomize data which will be used during our test. Not on the data in body, but also in URLs.

Randomization in Postman

Postman (same as google) really want to help you as much as possible. Their library for randomization (called Dynamic variables) is really huge. You don’t need to write anything by yourself, almost all is there. Have a look:

  • Commons — e.g. guids, uuids, timestamp
  • Text, numbers, and colors — e.g. bool, letters, words
  • Internet and IP addresses — e.g. ip, mac, 15-character alphanumeric password
  • Names — e.g. first, last, prefix
  • Profession — e.g. job name
  • Phone, address, and location
  • Images
  • Finance — e.g. bank account, credit card number, currency symbol
  • Business — e.g. company name
  • Catchphrases — e.g. catchphrase, catchphrase descriptor
  • Databases — e.g. database column name, database collation
  • Dates — e.g. future datetime, recent datetime
  • Domains, emails, and usernames
  • Files and directories — e.g. file extension, file path
  • Stores — e.g. price between 0.00 and 1000.00, product material
  • Grammar — e.g. verb ending in -ing, phrase, word
  • Lorem ipsum — e.g. word, sentence, paragraphs

All above, can be used just like that — in request body, pre-request Script, Tests script, even as global or environment variable.

Randomization in jMeter

Randomization in jMeter is not so user-friendly as in Postman. It’s mainly focused on the common sense of the user. There are not so many groups, but all the same is possible there. It’s possible, but it requires more effort from the user to write the logic responsible for data generation ( have a look on the official docs). Out of the box, we can have:

  • Random — which generate a random number
  • RandomDate — which generate random date within a specific date range
  • RandomFromMultipleVars — extracts an element from the values of a set of variables separated by |
  • RandomString — generate a random string
  • UUID — generate a random type 4 UUID

That’s all about the default methods (delivered by jMeter) which could be used. But do not disregard the power of the methods, as these are enough (in most cases) to generate any type of random data you wish.

I encourage you to be familiar with both documentation (Postman and jMeter) — as they have pretty well definitions of the above — which should help to understand what could be used where and how…

Exemplary use cases

So, how to use it… As it doesn’t need to be obvious. And a good example is always welcomed.

Postman example

In case of Postman UI, it’s really easy ride. As, if you start writing the following, postman will start to try to help you by suggested option. What you should type:
​’{{$random}}.
No matter if you’ll start in the URL or in the body. Have a look on an example from URL:

And here example in the request body:

Pretty awesome, right?! As the code was self written. The same can be used in the pre-request script or in the Test body. Using similar syntax, you can even make a random global or environment variable. Here is an example from the pre-request body script:

var randomVar = pm.environment.replacein("{{$randomfirstname}}");
console.log(randomVar);
pm.environment.set("mati-qa-random-1", randomVar);

So, here you can see, that pm.environment.replacein() method is doing the trick. It’s responsible for access to the native random library. Unfortunately, here postman is not willing to help us with the variable name. That cause, you need to know, what are you looking for.

jMeter example

jMeter is a bit easier in case of using random variables, or maybe a bit more complicated if you will know the tool better. However, let’s leave it for later and focus on similar use cases. As I wrote above, we don’t have here so many ready to sue variables. Instead of that, we have only couple methods / functions which can be used out of the box. Here is an exemplary use of the random method in the request URL:

As you can see, in that case, the part responsible for data generations is as follows:

${__RandomString(10,abcdefgijklmnoperstuwvxyz)}

So, we’ll use RandomString function, which will generate 10-letter word, which will contains of ‘abcdefgijklmnoperstuwvxyz’ letters. In the results tree view, we can check what was generated -

Regarding body data — here the syntax is the same. To generate a random number, we need to use Random() function, which will generate the number in the range between 0 and, 100000:

And again we can check the result of the method in the result tree view:

Playing with a pre-scripts in a jMeter is a totally different story (thank in Postman). As there you have a bunch of stuff which can be used as a pre-scripts.

However, BeanShell Preprocessor if the closest to the pre-script in postman.

Conclusion

As you can see, both tools are pretty awesome. Postman is really easy, and user-friendly. For basic stuff, if you will not use it too much, it should be enough. You can always you it together with Newman, which should extend it a bit, and help to work around the limitations. But, the limitations… It’s not the best choice for stress/performance tests purposes, and if you don’t like to pay (as me). And here is an alternative — jMeter. A bit more effort, but free and dedicated to stress/performance tests. Easy to migrate collection from Postman to jMeter — as I showed in one of my previous posts. There is also a UI, in which the use of the tool may become really intuitive, if you get use to naming conventions.

So, have fun and experiment…

--

--

No responses yet