How to Create and Manipulate Custom Variables

When you are scripting and recording your scenarios with NeoLoad often the complexity of your application is not as cut and dry 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 choosing 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 while it 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, require 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:

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).

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.

Random Integer and Random String each provide 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).

Note also there is a Value change policy which 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) generate entirely random text-based values. 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 the 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.

Learn More

Discover more load testing and performance testing content on the Neotys Resources pages, or download the latest version of NeoLoad and start testing today.

If you have suggestions or would like to participate in this conversation, please let us know within the Neotys Community.

Leave a Reply

Your email address will not be published. Required fields are marked *