Set Variable Value Operation

Applies to LoadComplete 4.97, last modified on May 20, 2019

Use the Set Variable Value operation to assign values to variables in your scenario or project.

  • See Modifying Correlation Data

  • It might be convenient to place this operation (or operations) at the beginning of your scenario. This way you will easily see the variables used in your scenario and the values assigned to them.

The Think Time edit box at the top of the editor specifies the number of milliseconds the operation will wait before it starts executing.

Variable

The name of the variable to assign the value to, preceded by the @ character: @VariableName. You can specify a variable defined in the current scenario, or a project variable defined in the Variables collection of your project. If the specified variable does not exist, it will be added to the current scenario. To select an existing variable from the list, click in the Variable or Value column.

Expression

The value to be assigned to the variable, or an expression or variable whose value will be assigned to the variable.

Note: Do not enclose string values into quotes.

To assign a specific value to the variable, enter it as a Value:

Assigning a value to a variable

To copy the value of another variable, specify the name of the source variable preceded by @: @VariableName.

Assigning the value from one variable to another
Using Functions

You can specify complex expressions with functions, such as Sum(@OrderId, 5) or Concat ("Hello", @UserName):

  1. Select a function from the drop-down list in the Value cell:

    Selecting a function
  2. Specify parameters of the function. Parameters can be hard-coded values, variables (@VariableName) or other functions. To use a function result as a parameter, change a parameter’s Value to a function name.

    Specifying function parameters
Note: If the specified expression cannot be calculated (for example, the parameters are invalid), the variable value will not be changed.
Numerical Functions
Function Description Example
Arguments Result

Sum

Sums two or more numbers.

Number 1 = 2
Number 2 = 3
5

Power

Raises a number to the specified power. Uses the following parameters:
  • Number - Specifies a number whose exponentiation you want to get.

  • Power - Specifies an exponent.

Number = 2
Power = 3
8

Sqrt

Returns a square root of a specified number.

16 4

Divide

Divides two numbers. Uses the following parameters:

  • Dividend - Specifies a numerator.

  • Divisor - Specifies a denominator.

Dividend = 16
Divisor = 2
8

Subtract

Returns a difference of two numbers.

Number to subtract from = 13
Number to subtract = 5
8

Multiply

Returns a product of two numbers.

Multiplicand = 2
Multiplier = 8
16

Abs

Returns an absolute value of the specified number.

-16 16
String Functions
Function Description Example
Arguments Result
Concat Combines the text of multiple strings str1
str2
str1str2
Substring Returns a fragment of a string, starting from the specified position and having the specified length.

Has the following parameters:

  • String - Specifies a string from which a fragment will be retrieved.

  • Start position - A zero-based position of a character where the needed fragment starts.

  • Substring length - The number of characters in the fragment.

String = abcdefg
Start position = 0
Substring length = 2
ab
Find Finds the first occurrence of a text fragment in the specified string and returns the zero-based position of the first matching substring.

If the function fails to find the sought-for fragment, it will return -1.

Has the following parameters:

  • String to search in - Specifies a string where the function will search for the fragment.

  • Substring to find - Specifies the fragment to search for.

  • Offset - Specifies the initial position of the search. By default, the search starts from the beginning of the initial string (Offset = 0).

String to search in = abcdefg
Substring to find = ef
Offset = 0
4
Extract RegExp Returns a string fragment that matches the regular expression.

Has the following parameters:

  • Source string - Specifies a string in which the function will search for the fragment.

  • Regular expression - Specifies a regular expression, matches to which the function will search for. For information on the regular expression syntax, see Regular Expressions Syntax.

  • Match group to extract - Specifies a subexpression (group) in a regular expression a match to which the function will extract, in the $number format, where number is a subexpression position in the regular expression.

    You can specify a combination of several subexpressions or combine them with text. For example, $1$2 or $1-$2.

    See Working With Subexpressions.

Source string = username=Tester
Regular expression = username=(\w+)
Match group to extract = $1
Tester
Replace Replaces a fragment in an initial string with the specified substring and returns the resulting string.

Has the following parameters:

  • Source string - Specifies a string to be processed.

  • Substring to replace - Specifies a substring whose occurrences will be replaced.

  • Replacement string - Specifies a string that will be substituted into the initial string.

  • Replace all - A boolean value that specifies whether the function will replace all occurrences of the specified fragment or only the first occurrence.

  • Ignore case - A boolean value that specifies whether the search should be case-sensitive or not.

Source string = username=Tester
Substring to replace = Tester
Substring = Demo
Replace all = False
Ignore case = True
Username=Demo
Upper case Converts a string to the upper case. test TEST
Lower case Converts a string to the lower case. TEST test
String Encoding/Decoding Functions
Function Description Example
Arguments Result
URL decode Replaces URL-encoded characters in the specified string with their textual equivalents. John%20Doe John Doe
URL encode Replaces spaces, colons, commas, and other characters of the specified string with their URL-encoded equivalents. John Doe John%20Doe
HTML decode Replaces HTML entities with appropriate characters. & &
HTML encode Replaces special characters with appropriate HTML entities. & &
\x decode (2 hex digits) Replaces symbols specified in a hexadecimal format with appropriate characters.

The function expects the 2 hexadecimal digits after the \x prefix.

\xD8 O
\x encode (2 hex digits) Replaces symbols with appropriate hexadecimal characters. 16 10
\x decode (4 hex digits) Replaces symbols specified in a hexadecimal format with appropriate characters.

The function expects 4 hexadecimal digits after the \x prefix.

\x12A1 ?
\x encode (4 hex digits) Replaces symbols with appropriate hexadecimal characters. 16 0010
Calculate MD5 hash Returns the MD5 hash of the specified string. test 098f6bcd4621d373cade4e832627b4f6
Note: In order for the hexadecimal encoding and decoding functions to work correctly, the appropriate system code page must be installed on the computer where the scenario is simulated. You can learn about code pages in the MSDN Library.

This page provides summary information on the operation like the number of found errors, the list of variables used, and so on. Information on the page is read-only.

You can find information on issues in operation properties in the Summary page. Also, information about the erroneous settings is displayed in the editor’s header area.

See Also

Operation Reference
Using Variables
Editing Scenarios

Highlight search results