Dynamic Datasets

Datasets can be used to supply dynamic or unique values to your scripts, so your load test can submit different data to the server for each bot or iteration.

For example:

  • Logging in with a different username and password each time.
  • Submitting a registration form with unique personal data for each user.
  • Searching for any of 100 search phrases at random.

For most web applications, testing with dynamic data is important. It’s more realistic and it may force the application and database to work harder than if you submit the same data over and over.

Editing Datasets

Editing datasets in Loadster is like using a spreadsheet. Each row signifies a separate entry in the dataset, and you can use multiple columns to supply multiple fields related to the same row.

A dataset with data
A dataset with data

For example, if you are providing user data where each user has a corresponding first name, last name, and email address, you can store these as columns to make certain they do not get mixed up with one another.

Importing CSV data into a dataset

To save time, you might want to import data into your dataset from a CSV file. You can do this by first creating an empty dataset, and clicking the Import CSV… button.

Using Datasets in Scripts

Datasets must be mapped to script variables before you can use them in your scripts. To map (or “bind”) a variable, click Bind Variables at the top of your script.

Binding datasets to dynamic script variables
Binding datasets to dynamic script variables

Even though we treat them as variables, they are actually more like cursors in a database, because they can possibly return a different value each time you invoke them.

The Bind Variables dialog lets you give the variable a name, and configure how often new values should be selected from the dataset.

Example of a script variable called 'name' that pulls from the Names dataset
Example of a script variable called 'name' that pulls from the Names dataset

Whatever variable name you enter here will be available in your script with the ${} notation. For example, if you entered a name of user, you can use it in your script as ${user}.

If your dataset has multiple columns, an entire row will be selected each time, and the variable will be an array. For example, in a two-column dataset containing usernames and passwords, the username would be in ${user[0]}, and the password in ${user[1]}.

Dataset variable selection order

When you reference a dataset variable in your script, the variable is assigned a value from the underlying dataset. You can specify whether to pull new rows from the dataset sequentially or randomly.

  • sequentially - The rows in the dataset are read in order, starting from the beginning. If the end of the dataset is reached, it starts over.

  • randomly - The rows in the dataset are read at random.

Dataset variable selection frequency

You can also control how often a new row is pulled from the dataset.

  • for each bot - Each bot assigns a value to the variable when it’s first encountered, and it keeps that value for the duration of the test, even if the bot runs multiple iterations.
  • for each iteration - Each bot assigns a value to the variable when it’s first encountered, and it retains that value for the rest of the iteration, but a new value is assigned in each subsequent iteration.
  • for each occurrence - Every time the variable is referenced in a script, a new value is pulled from the dataset.

Using a dataset variable in your script

Once you have bound a dataset variable, you can reference it in the script with the following variable notation:

  • ${Email}
  • ${ProductID}
  • ${FirstName}

If your dataset has multiple columns, you can specify which column to use with this zero-based array notation:

  • ${User[0]}
  • ${User[1]}
  • ${User[2]}

You can leave off the [0] to signify the first column. In other words, the following are identical:

  • ${User}
  • ${User[0]}

Where to use variables

Whenever Loadster comes across your variable, it substitutes the value from the dataset. You can use variables almost anywhere in a step.

To learn more about variable syntax and advanced expressions, check out Variables and Expressions.

Other Ways To Set Script Variables

Variables are not only populated from datasets. You can also set variables yourself during script runtime, by capturing output from the site or application you are testing.

In a protocol script, you an do this with Capturing Rules.

You can also set a variable yourself in a Code Block with bot.setVariable('myVar', 'value').