Skip to content

Variables

The variable page lets you configure, in one place, predefined variables.

To open the variables page, simply click on the Configuration > Variables button in the Virtual User page.

Constant Variable

The left part of the page lists all the variables for the current project. Variables declared in ths list are common to all the VUs of a project. You can use the headers of this list to filter or sort it.

The right part displays the selected variable configuration. It is only editable if a variable is selected.

Three types of variables are available:

  • Constant Variables that associate a single value to the variable name,
  • Random Variables that associate a single random value to the variable name,
  • CSV Variables that uses a CSV formatted file for the values of the variable.

Add Variable

The following procedure explains how to add a variable configuration:

  1. Click on the Add button,
  2. A dropdown appears,
  3. Select the type of variable to add: Constant, Random or CSV,
  4. A new variable name variable_n is added to the list and selected.
  5. Edit the input fields on the right,
  6. Close the variable panel by clicking on the Close button positioned at the top right corner.

Remove Variable

The following procedure explains how to remove a variable configuration:

  1. Click on the variable to remove in the variables list,
  2. Click on the Delete button.

Info

You can use SHIFT + click or CTRL + click to select multiple variables and delete them all at once.

Warning

As variable are commons to all VUs of a project, variable removal and update may affect VUs that you are note currently editing.

Constant Variable Configuration

The following procedure explains how to change a Constant variable configuration:

  1. Click on the variable to update in the variables list,
  2. Edit the input fields on the right,
  3. Close the variable panel by clicking on the Close button positioned at the top right corner.

For each Constant Variable, you can edit:

Property name Description
Name The variable name. To inject it, use the ${...} syntax. E.g. in the above screenshot, you could inject constant_value using the ${constant_variable} syntax.
Description The variable description
Value The constant value of the variable

Note

Edited variables are all updated when you close the variable modal. But variable addition / removal is done immediately.

Random Variable Configuration

The Random Variable is used to generate random numeric strings.

The following procedure explains how to change a Random variable configuration:

  1. Click on the variable to update in the variables list,
  2. Edit the input fields on the right,
  3. Close the variable panel by clicking on the Close button positioned at the right left corner.

For each Random Variable, you can edit:

Property name Description
Name The variable name. To inject it, use the ${...} syntax.
Description The variable description
Minimum Value The Random Variable range lower bound.
Maximum Value The Random Variable range upper bound.
Output Format The output format of the generated value. Leave blank for a simple number output. It uses the java.text.DecimalFormat. For example 000 generates numbers with at least 3 digits, and USER_000 generates output of the form USER_nnn.

CSV Variable Configuration

A CSV file consists of any number of records, separated by line breaks of some kind; each record consists of fields, separated by some other character or string, most commonly a literal comma or tab.

Each time a Virtual User is executed, it uses a line of the CSV file and gets one variable for each column. E.g. if you run a scenario for one hour, with a VU that takes 5 minutes to execute, you would need 12 lines in your CSV file to allow each VU ran to have its unique set of variables.

The CSV file parsing is configured in the Configuration tab. And the variables naming is done in the Column tab. The Column tab also shows a preview of the extracted values.

The following procedure explains how to change a CSV variable configuration:

  1. Click on the variable to update in the variables list,
  2. Enter a name and description,
  3. In the Configuration tab, select a CSV file to upload,
  4. Select encoding, delimiter and other options (explained bellow),
  5. Switch to Columns tab,
  6. For each column, type the name of the corresponding variable,
  7. Close the variable panel by clicking on the Close button positioned at the right left corner.

CSV Variable Configuration

Property name Description
Name The variable name. To inject it, use the ${...} syntax.
Description The variable description
File The CSV file of the variable
Shuffle Rows Shuffles the CSV file lines before executing the test
Encoding The CSV file encoding, leave blank if UTF-8
Delimiter The character or string used to separate the fields in the uploaded CSV file. Usually a comma
Allow quoted data A value may be enclosed in double-quotes if this option is selected
Sharing mode Private or Shared, if private each VU instance will use its own data set
Recycle values on EOF Should the file be re-read from the beginning when reaching its end? If set to false the value is set to <EOF> when the end of the file is reached
Stop VU on EOF Should the Virtual User be stopped when the end of the file is reached. Can only be activated if the Recycle values on EOF option is not

Note

If Allow quoted data is enabled, values in the CSV file may be enclosed in double-quotes. These are removed. E.g. you use a comma delimiter but one of your values contains a comma character. You can escape this value by placing it between quotes.

To include double-quotes within a quoted field, use two double-quotes. For example, with the CSV content (comma character used as a delimiter and quoted data allowed):

first,"second",last
1,2,3
1,"2,5","4""5"

Column one Column two Column three
first second last
1 2 3
1 2,5 4"5

Columns

The column tab gives a preview of the extracted values:

CSV Variable Columns

You can use it to check if your configuration gives the expected output.

Each column header is editable. It lets you name each of the variables. E.g. in the above screenshot, you could inject id using the ${id} syntax and value using ${value}.

Tip

You can leave empty column names. In this case the first row of the CSV file is used as variables names.

Skip to next line

CSV files in OctoPerf are parsed once every iteration. If you need to skip a line or just want to parse the whole CSV in one iteration, you can use the __CSVRead function.

CSV Read example

Example for a file named credential.csv:

  • ${__CSVRead(resources/credentials.csv,0)} will be replaced with the first column of the current line,
  • ${__CSVRead(resources/credentials.csv,1)} will be replaced with the second column of the current line,
  • ${__CSVRead(resources/credentials.csv,next())} will skip to the next line.