Expression
Expressions can be specified at different places of the test script and then evaluated during the test run.
Settings which require an expression
Action element, Extended Settings tab, Condition input field
element (below a Choose element), When tab, Condition input field
Assignment element, Assignment tab, Value input field
Specify an expression according to the syntax specified below. The expression which yields a Boolean value is evaluated at runtime. If you use a test script variable in the expression, then you need to specify the variable with a placeholder operator.
TempPath = 'D:\Temp'
Syntax
The following syntax is defined in Backus-Naur form.
or-expr ::= and-expr { bool-or and-expr} and-expr ::= expr { bool-and expr } expr ::= simple-expr { relation-op simple-expr } simple-expr ::= [ sign ] term { addition-op term } relation-op ::= "=" | "<>" | "<" | "<=" | ">" | ">=" sign ::= "+" | "-" term ::= factor { multiplication-op factor } addition-op ::= "+" | "-" factor ::= IDENT {call-spec}| number | STRING | "(" or-expr ")" | "NOT" factor | SCOPEACCESS | "TRUE" | "FALSE" call-spec ::= "(" {argument-list} ")" argument-list ::= or-expr {"," or-expr} multiplication-op ::= "*" | "/" | "DIV" | "MOD" number ::= INTEGER | REAL bool-and ::= "AND" bool-or ::= "OR" IDENT ::= Letter { Letter | Digit } SCOPEACCESS ::= "$" IDENT { "." IDENT } STRING ::= """ { String-Char } """ INTEGER ::= Digit-Seq REAL ::= REAL ::= Digit-Seq "." [ Digit-Seq ] [ Scale-Factor ] | Digit-Seq Scale-Factor Letter ::= "A".."Z" | "a".."z" | "_" Digit ::= "0".."9" String-Char ::= (any char except """) | """" Digit-Seq ::= Digit { Digit } Scale-Factor ::= ("E" | "e") [ "+" | "-" ] Digit-Seq
Constants
TRUE
::= 1FALSE
::= 0
Example
In the following example, a test script is created which presents the most common uses of Test Manager expressions. The test script can be executed at any time. By clicking the Show parameters button in the resulting test report, you can inspect how the values of the variables change over the course of the test script. The example is subdivided into smaller chapters to make it easier to understand. These are based on each other.
Basic arithmetic
Assignments of literals
Expressions can be used together with Choose elements to implement control flows:
Create a new test script.
Add an Assignment element with the following contents:
four := 4
Explanation:
This expression assigns the value 4 to the variable
four
Variables must not be inside curly brackets.
The value 4 is a numeric literal. It must not be placed inside curly brackets.
Assignments of expressions
In addition to constant values, the results of expressions can also be assigned.
Add an Assignment element to the test script with the following contents:
thirtySix := (4 + 5) * four
Explanation:
The result of the expression (36) is assigned to the variable
thirtySix
Neither of the two variables may be inside curly brackets.
Because the variables contain numerical values, they can be used with arithmetic operations (+, -, *, /).
The order of arithmetic operations corresponds to the usual mathematical order (multiplication before addition).
Arithmetic operators
In addition to the + and * operators, there are also other operators.
List of all operators:
+
-
/
MOD
DIV
Add two more Assignment elements to the test script with the following contents:
real := thirtySix MOD 11 DIV 2 / 4.0 integer := thirtySix MOD 11 DIV 2 / four
Explanation:
The
MOD
operator stands for modulo operation and always returns an integer value. The expressionthirtySix MOD 11
therefore results in the value 3.The
DIV
operator stands for integer division and always returns an integer value. The expression"3 DIV 2"
therefore results in the value 1.The operator
/
stands for floating-point division and returns a real value if the divisor is a real value. If the divisor is an integer value, then it returns an integer value. The expression1 / 4.0
therefore results in 0.25, while the expression1 / 4
results in return the value 0.The operators
MOD
,DIV
, and/
have the same mathematical order of operations as multiplication. The expressions are evaluated from left to right. Consequently, the expressionthirtySix MOD 11 DIV 2 / 4.0
yields the value 0.25 and the expressionthirtySix MOD 11 DIV 2 / four
yields the value 0.Arithmetic operators with a real value always yield a real value as the result.
MOD
andDIV
can be used only with integer values.
Logical operations
In addition to arithmetic, it is also possible to perform logical operations. There are comparative operators and links. Logical operations yield the Boolean values TRUE
and FALSE
.
Comparative operators
Comparative operators can be used to compare two values with each other.
List of all operators:
=
(equal to)<>
(not equal to)<
(less than)>
(greater than)>=
(greater than or equal to)
Both variables and constants can be used in comparisons. The result of a comparison operator is always a Boolean value.
Add six more Assignment elements to the test script with the following contents:
equal := 4 = 4 notEqual := 4 <> 3 lessThan := 2 < 4 lessEqual := 4 <= 4 greaterThan := 4 > 2 greaterEqual := 4 >= 4
These assignments are selected so that they all return the value TRUE
.
Links
The Test Manager supports the following link operators:
AND
OR
Add two more Assignment elements to the test script with the following contents:
and := true AND false and := true AND true
Explanation:
Valid logical values are
true
andfalse
. The values are not written in quotation marks.AND
results intrue
when both sides of the operator aretrue
. In all other cases,AND
results infalse
.
Add three more Assignment elements to the test script with the following contents:
boolValue := true or := boolValue OR false or := false OR false
Explanation:
Boolean values can also be assigned to variables.
Variables can also be used in logical expressions. They must not be inside curly brackets.
OR
results intrue
when at least one side of the operator istrue
. If both sides arefalse
, thenOR
also results infalse
.
Control flow
Choose
"Choose" elements make it possible to execute different expressions based on a condition.
Add a new Choose element to the test script.
Enter the following expression as a Condition:
thirtySix = 36
Add the following Assignment under the Condition:
fruit := "apple"
Add the following Assignment under Otherwise:
fruit := "banana"
Explanation:
When the selection is reached, the condition is first evaluated
To compare the value of a variable in a condition, it must not be enclosed in curly brackets
Because in this case the value of
thirtySix
corresponds to the value 36, the condition returnstrue
As a result, the subordinates of the condition are executed.
This assigns the value
"apple"
to thefruit
variable.
Macros
To use variables in macros, they must not be enclosed in curly brackets, as is the case with the normal use of variables. This rule applies to all macros.
Add an Assignment element to the test script with the following contents:
concated := CONCAT("delicious ", fruit)
Explanation:
The string
"delicious"
and the value of the variablefruit
are combined and result in the new value"delicious apple"
.
Parameters
Test Manager expressions can also be used in the parameters of test actions. They follow the same rules as in all other use cases.
Add a new Test Case.
Add a new Test Action to the test case.
Select
ExecuteScript
as the action in the test action and open the Parameters tab.As Input Parameters, add a variable named
forty
.Add the following statement to the Variable column of
forty
:thirtySix + 4
Explanation:
The expression is evaluated before it is available as the variable
forty
in the test action.The variable
forty
therefore has the value 40 in the test action.In addition to Test Manager expressions, it is also possible to pass scripting objects to other test actions via the parameters. For example, a project can be opened in a script, which can then be used in other test actions.