Blog

How to create and manipulate custom variables

Performance testing

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

Author:

Tricentis Staff

Various contributors

Date: May. 18, 2020

When you are scripting and recording your scenarios with Tricentis NeoLoad, often the complexity of your application is not as cut-and-dried as a simple one, two, three start-to- finish set of steps. Often you’ll need the ability to dynamically select what is going to happen next based on previous actions in the user path and possibly choose multiple outcomes or provide data. This is where variables are treasured, and when defined, they hold data point values that can then drive desired scripted decisions.

Variable manipulation is often one of the main reasons we even use computing technology. Sometimes we might need a list of data — take a list of employees, for example. We may need to manipulate specific tasks or areas that can be accessed based on the length of time an employee has been at the company. In NeoLoad, we bring this kind of timestamp variable manipulation to life through exposure of the data table with employee records, which helps determine various outcomes based on what each given record’s date/time returns.

There are required values in any application like cookies (which are dynamic and unique — automatically handled by NeoLoad), session IDs, and timestamps. Or perhaps the total number of items, the total cost of a random set of purchases, the length of time since the last login, etc. As you can see, there are plenty of reasons that variables are needed, requiring that they are defined/utilized within the user paths of NeoLoad.

Custom variables defined

The different types of custom variables available to you in NeoLoad include Counter, List, File, SQL, Random Integer, Random String, Constant String, Password, Date, Current Date, Random UUID, Shared Queue, and JavaScript. To see this list, click Edit -> Variables -> Function button on lower left:

Tricentis Neoload function button

Two variable options available include List and File, which are similar in that each utilizes a data table similar to a spreadsheet. The difference: one is manually entered into NeoLoad, the other is based on a file type like comma delimited, which is then populated and referenced, for instance. Within the list and file variables, you are also presented with Scope and Order selection options regarding how the values are distributed. (See Order drop-down of Random list dispersion below).

Variable values distribution policy screen

Similar to the file variable, you can also define an SQL variable. Note this requires that the connection credentials be used for database access. The SQL variable supports MySQL, Oracle, DB2, PostgreSQL, Microsoft SQL, as well as custom options. Once connected to the database, you can query just as you would within SQL along with a test button to confirm both the credentials and the query are valid.

Tip: The Password variable is hidden (unless the eye icon is clicked), and works when a password field is required in the user path.

Hidden password variable tip

Random Integer and Random String each provides a similar interface allowing for a defined name, description (optional), minimum/maximum lengths, and the option to select predictable randomization. (Note: Predictable option items will still be random. However, the same sequence of random variables will be selected every time the series is run. Thus, randomly generated values have comparable values for two identical tests).

Random integer and random string screen

Note also there is a Value change policy that lets you select the trigger that will move on to select the next value: on each use, request, page, iteration, or for each virtual user instance.

Each random string, random integer, and also Random UUID (Universal Unique Identifier) generates an entirely random text-based value. Random UUID, a 128-bit number used to uniquely identify some object or entity on the Internet, can be used to isolate a unique item you wish to track more closely. You have the option of generating an all uppercase UUID, which also comes with predictable randomization.

The Counter variable is extremely useful for support as counting utility aid. For example, if you would like the test to stop when a select number of transactions has occurred, this variable enables you to select Stop the test. This field can also act as a great troubleshooting tool, especially if you want to know how many times something has occurred. You can set the minimum (start) and maximum (end) and ideal increments associated.

Shared Queue uses a .CSV swap file to share data from another file into a test. It works in conjunction with the Variable Modifier function allowing you to consume into a variable — to which the value in the queue is copied; the syntax is variableName, omitting ${}. Shared queues are variables that enable dynamic content to be shared among virtual users. They follow the Producer-Consumer concept. Also, they are used just like any other NeoLoad variable and may be combined with other variables or static content.

JavaScript variables are custom scripts callable from a variable with referencing as, i.e., ${MyJavaScript_Variable} which can come in handy depending on your requirements.

Putting it all together

There are many creative and different ways that variables can be used together and within specific functions on the user path to accomplish some different outcomes. The implementation choices, which go beyond the scope of this article, are only limited by that of the designer’s imagination.

Happy scripting and be sure to check out the following documentation Variables in NeoLoad.

The post was originally published in May 2018 and was most recently updated in July 2021.

Performance testing

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

Author:

Tricentis Staff

Various contributors

Date: May. 18, 2020

Related resources