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 Data

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

Each time you reference the variable in your script, Loadster will pull a row from the underlying dataset. You can specify whether to pull new rows sequentially or randomly.

  • sequentially - The first time a bot reads a row from the dataset, the first row will be used, and then the second, and so on. First come first serve. Once the end of the dataset is reached, it starts over from the beginning.

  • randomly - A random row is pulled from the dataset each time, regardless of what row was pulled previously.

Dataset Variable Selection Frequency

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

  • for each bot - Each bot selects a new row from the dataset, and then keeps it for the duration of the test, even if the bot does multiple iterations.
  • for each iteration - Each bot selects a new row at the beginning of each iteration. If the variable shows up multiple times in the script, it will have the same value, but if the same bot starts a new iteration, it will have a new value.
  • for each occurrence - Every time the variable is used in a script, a new row is pulled from the dataset.

Using the 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').