Description
Use the Set Variable Value operation to assign values to variables in your scenario or project.
Using the Operation
-
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.
Position
Number of occurrences: | Unlimited. |
Parent operations: | Any other operation. If the scenario editor displays pages and connections, the operations cannot be placed between a page and a connection. |
Child operations: | The operation cannot have child operations. |
Operation Think Time
The Think Time edit box at the top of the editor specifies the number of milliseconds the operation will wait before it starts executing.
Operation Properties
Properties Page
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:
To copy the value of another variable, specify the name of the source variable preceded by @: @VariableName.
Using Functions
You can specify complex expressions with functions, such as Sum(@OrderId, 5)
or Concat ("Hello", @UserName)
:
-
Select a function from the drop-down list in the Value cell:
-
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.
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 = 2 Power = 3 |
8 |
Sqrt |
Returns a square root of a specified number. |
16 | 4 |
Divide |
Divides two numbers. Uses the following parameters:
|
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 = 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 = 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 = 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 = 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 |
\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 |
\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. |
Summary Page
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.
Information on Errors and Warnings
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.