Parameterize values

This topic describes how to enhance your DevWeb scripts with parameterization.

Parameterization overview

When you build your DevWeb script to emulate a business process, you create a script that contains specific values. Suppose you want to perform the script's actions (such as query or submit) using different values from those recorded. To do this, you replace the values with parameters. This is known as parameterizing the script.

During the test run, DevWeb substitutes the parameter with values from a data file that you specify, in the method that you specify in the Parameter resource file (parameters.yml).

Tip: Check out the video: Tutorial #6: Using parameters.

Back to top

Parameter data files

Parameter data files hold values that Vusers can access during script execution.

A parameter data file is a CSV (comma separated values) file. One file can contain values for many parameters. Each column contains the values for one parameter. The first row in the column represents the parameter name, while each subsequent row represents an additional value.

In the following example, the data file contains the "id" and "first_name" parameters:

id,first_name

120,John

121,Bill

122,Tom

Back to top

Parameter resource file (parameters.yml)

The parameters.yml file describes how to use parameters in your script. This file is stored in the script folder.

Each parameter requires its own properties, as shown in the sample below.

parameter.yml arguments

The following table describes the parameters.yml properties.

Property Description
name

The name of the parameter that can later be used in the code.

type

The type of data source for the parameter.

Supported type: CSV, a comma-separated table of values where each column represents one parameter. The CSV must contain a header row defining the names of the columns.

fileName

The name of the CSV file in the script folder that contains the parameter data.

columnName The name of the column (in the CSV file) from which to take the values for the parameter that it represents. This is defined in the first row of the CSV file.
nextValue

The logic used to know when to collect the next value, determined as follows:

  •  once. The value is retrieved only once per the entire test run, and remains the same value throughout the run.

  • iteration. A new value is retrieved per each iteration and remains the same value throughout the iteration.
  • always. The value is retrieved every time the parameter is used.

Note: nextValue is ignored when nextRow is set to same as <parameter name>.

nextRow

The logic used to know how to select the next value, determined as follows:

  • sequential. The next value is the value directly following the current value in the same column.

  • random. The next value is a random value from the same column.
  • same as <parameter name>. The next value is taken from the same row as the current value of <parameter name>. This is useful, for example, when matching a password for a username.

    When same as <parameter name> is used, nextValue and onEnd are ignored.

  • unique. The next value is chosen from a unique block within the parameters file that is unique to the current Vuser. To control the size of the block, set the blockSize parameter.

blockSize

Used only when nextRow is set to unique.

  •  auto. The block size is automatically calculated by the engine based on the total number of Vusers scheduled to run.

  •  <number>. The size of the block.
onEnd

Determines what happens when all the values have been used, but the script still needs more values. The supported option is loop, meaning

the first value is used as the next value.

If this property is left undefined, an error is reported when all values have been used.

Note: onEnd is ignored when nextRow is set to same as <parameter name>.

firstDataRow

Defines the starting row for selecting values from the column.

The values in the rows before the starting row are never used for the parameter, even when selection is looped or random. For example, if firstDataRow: 4, then the values in rows 1 to 3 are never used.

Note: The firstDataRow number refers to the first row of actual data; the row containing the column names is ignored.

User arguments from runtime settings

The parameters.yml file can use arguments defined in the runtime settings (rts.yml), by specifying the user argument key surrounded by %%.

Example

In parameters.yml:

parameters:                    
  - name: myParam4 
    type: csv
    fileName: "%%myfile%%"
    …

The referenced argument added to rts.yml:

userArguments:
  myfile: "./data.csv"

For details on adding user arguments to the rts.yml file, see Add additional attributes.

Back to top

Using parameters in your script

To use parameter values during a test run, you substitute the constant values with parameters.

Parameters are exposed to the script through the load.params variable. All of the information required for the parameter, such as the location of its data file, is indicated in the parameters.yml file described above.

You can add the parameter to a string with the standard JavaScript syntax. For example:

var paramValue = load.params.myParam;
var nextParamValue = load.params.myParam; //if nextValue is "always" this will be a new value
var someString = `The value of myParam is ${load.params.myParam}`;

For details, see Parameters in the JavaScript SDK documentation.

Back to top

See also: