Blog

How to extract dynamic values and use NeoLoad variables

Performance testing

Learn more about continuous performance testing and how to deliver performance at scale.

Author:

Tricentis Staff

Various contributors

Date: Feb. 03, 2021

Designing a load test involves the creation of a script — a set of calls, requests, and actions to an application server. The “script,” in its raw form, is usually a recording of an emulated user interacting with the application.

With any typical user session accessing an application server, there are parameters (and values) that give this specific session its unique fingerprint. Why is this important? If left unmodified, these parameters with recorded values will play back to the server in their original value(s). The initial static values are no longer valid and were usually specific to the original recording, but not suitable for any playback of the script. Some of these parameters include session IDs, tokens, timestamp values, and universally unique identifiers (UUIDs), and must be different every time the script runs.

Dynamic parameters

The handling of these static values so that they appear dynamically distinctive each time a load test runs is called correlation, or what many refer to as-as the bread and butter of “design.” Many of the best load testing tools aid in the identification and handling of dynamic parameters. Some tools, like Tricentis NeoLoad, can automate handling the many occurrences of dynamic parameters through a feature called Frameworks. This can save hours and days designing and maintaining a script in preparation for load testing. Once you identify what is dynamic in your script and create correlation for it (extraction using a regular expression and replacement), you promote it to a Framework. This allows NeoLoad to search for dynamic values throughout your script and automatically handle the correlation. The time saved can be significant, which makes your job easier and less stressful.

Some examples of unique dynamic values that web applications use are in the form of timestamps. Since time is something specific to when an application and user is accessing the application, the value will eventually become invalid and need to be replaced with a variable that makes it dynamic. Most web applications use Epoch timestamp values, or current milliseconds from January 1, 1970. Take this screenshot below, for example, using a Google Ad Services request.

Tricentis NeoLoad - Dynamic parameters

It uses a value of “1519246164376” for the “random” parameter, which is the equivalent to Wednesday, February 21, 2018, 3:49:24.376 PM GMT-05:00 (Eastern US time zone). If you try to replay the script using this value after a day or more, the server is likely to reject your request, yielding a script error. With NeoLoad, you can replace this value with a variable based on current date using the current time in milliseconds pattern (Epoch time).

Session identification

Almost all web applications use some form of session identification to designate an individual user’s application access time, thus making it unique. This particular parameter will contain an alphanumeric value that is stored in a cookie, form field, or URL. The value can sometimes incorporate a timestamp (see above) or other more complex factors, which may be in the likeness of “jsessionID” or UUID. While NeoLoad typically handles session IDs very well, it can just as easily handle complex methods and correlation. No matter how it is dealt with, when a user (or virtual user) visits a website, it is given unique session info that is either valid for as long as the browser is open or for a specified amount of time. This is why it is essential to ensure that you’re using dynamic parameters.

Dynamic parameter identification

As you can see, it’s important to identify and handle parameters with dynamic values. Using static values from a recording will result in script and load test failure. Being able to determine what parameters are dynamic is equally as important as how you’re handling them. There are some fundamental ways (which this article will not go into), to help with identification — one common practice is to compare a recording to a playback of the same script, looking for value similarities. Pay attention to any errors in responses that might give clues to what was sent improperly. If a session ID that is assigned is invalid, you will likely generate a 403 or 500 status code. When it comes to request comparison to identify dynamic parameters, NeoLoad delivers a side-by-side view. For now, let’s focus on how to handle a parameter, once you recognize it is dynamic.

Tricentis NeoLoad - Dynamic parameter identification - advanced

In the example above, we’ll use an online public demo e-commerce application called “JPetstore,” in which you can shop for animals to purchase. After recording the simple scenario of going to the main page, selecting the “Cats” category (including type), and proceeding to checkout for purchase, we will examine a dynamic parameter for the sample user’s session. In the example, the application is using a jsessionID parameter in a cookie to set the session info for the user visit, as seen in the following screenshot of the response using Tricentis NeoLoad.

Tricentis NeoLoad - Variable extractor

Usually, once you identify where a dynamic parameter is, you can create a regular expression extractor. This way, the value of this parameter is extracted from the server response for each script run and user session/visit. NeoLoad has an easy way to create an extractor using a variable. To illustrate this, refer to the image of a regular expression extraction that allows you to use it as a NeoLoad variable later on (next step).

You will notice the value at the bottom of the window allows you to confirm that your regular expression is correct. This is the first part of correlation — identifying the dynamic value and creating its extractor using a regular expression. The next is a manual step where you’re value-replacing any requests using it with the variable. In this case, jsessionID, or within NeoLoad, ${JSESSIONID}. You would search for requests with the value “F47AC58DD1575B9CBBB1361944B5C571” and replace these with the NeoLoad variable from the extractor. In particular, this is where NeoLoad outperforms most of its competitors.

Tricentis NeoLoad - Dynamic parameter identification framework

As mentioned previously, NeoLoad’s Frameworks feature enables the automation of correlation, removing the time-consuming effort associated with dynamic parameters handling. It will even handle ALL occurrences of the dynamic parameters, so long as it matches the regular expression and can find a corresponding value in a request. Very often this can save dozens or more of hours trying to find and handle all your correlation throughout your scripts. To display this in-action, refer to the wizard and configuration (above) for promoting/converting an extractor where you already have a Framework.

Once the Framework is created, it will search and replace any matches it finds for the regular expression and corresponding value as illustrated below. As you can see, the value is now replaced by the extractor variable. This allows the script to extract the value from the server response whenever the script is run, replacing the value in the request, thus keeping it dynamic and current for each user iteration.

Tricentis NeoLoad - Dynamic parameter identification replace value

As the extractor replaced many occurrences of the jsessionID value throughout the process, you can see how much time can be saved; it will be automated for any future recordings. This means that there is no manual work required for this value going forward.

Conclusion

Correlation is the core of designing scripts used in load testing. It can be difficult and time-consuming, as you need to identify what is dynamic first; find the response that you can extract from, and match all the occurrences in requests for that regular expression extraction. NeoLoad makes this process easy and saves you time by automating your correlations through Frameworks. With NeoLoad, you have more time to focus on other challenges with your load tests, and not be set back by handling your dynamic parameters.

This blog was originally published in March 2018 and was refreshed in July 2021.

Performance testing

Learn more about continuous performance testing and how to deliver performance at scale.

Author:

Tricentis Staff

Various contributors

Date: Feb. 03, 2021

Related resources