What if you have to do extensive performance tests for a complicated webapp with login, search forms, etc.? If the tool you would use for this must be very powerful, opensource and have graphic interface – there is no way you can pass by JMeter. At this time I’ll tell about how to get dynamical data to be used inside JMeter tests. I’ll presume you’ve already worked with JMeter before and have at least knowhow about a standard test plan structure.
There are at least two possibilities to dynamically generate data:
- The first and very simple one is to write an external script. In this case we would request that script in our test plan through the WEB with the HTTP request client and parse in the data it returns. The advantage of this is simplicity, as JMeter can automatically parse the data for us. A disadvantage is that the script must be accessible anytime, which is not possible in some cases.
- The second way is to generate data inside JMeter. This is already partially possible with for example random variables. But beside this there are also request preprocessors available. With this we can get dynamic or pseudo dynamic data inside our test plan. The great advantage of this is the independency from external tools. From the other hand, some more preparations must be met and the arsenal is a bit more limited.
The way I’ll cover here is the second, cause here we get a standalone JMeter project with a local data source which makes running tests from any location possible.
So lets go. In this example we’re testing a hypothetical search form with multiple search fields. Of course we know the internal application algorithms and therefore can define corresponding search terms. The first thing we need is to collect the search terms into a CSV file and add a “CSV Data Set Config” element to our test plan. To do this, right click the test plan and choose Add->”Config Element”-> “CSV Data Set Config”.
The CSV file we using contains a list of unquoted terms delimited by tab. Each term must correspond to a variable defined in the “Variable Names” field. I’m using a simple name convention
To get randomized data from the file, the next step is needed. Here we add a preprocessor to one of the thread groups rightclicking it and choosing Add->”Pre Processors”->”BSF PreProcessor”.
As alternative for those who is familiar with Java, the “BeanShell PreProcessor” could be used or Java in the “Language” field could be be set. For now I’m using JS and defining a small function to get a number within the given range. Using it two variables COUNTRY and CUSTOMER with random contents are defined. Moreover, as we can’t pass arrays as variables, some as string defined array with three elements is directly passed to the request sampler.
Now we are so far to use the defined variables in some HTTP request. If you have no “HTTP Request HTTPClient” in the “Thread Group”, add it using Add->Sampler->“HTTP Request HTTPClient”. Then define request variables as follows:
As you can see, there is no person array definition in the variable list – it was passed directly to the HTTP request sampler from the BSF preprocessor and will arrive the sever as array.
Of course, we don’t always need a CSV to generate data this way.
That’s it, everytime the request beats, randomly selected data is used. So enjoy dynamic data in your JMeter project.