Dynamic expressions
Dynamic expressions are used if values are needed for test specification that are not generated until the TestCases have been executed.
Dynamic expressions can be used on both the Module and the TestCase level.
Examples:
-
the current date
-
the current first of the month
-
object numbers (order number that are created at runtime, etc.)
This chapter describes dynamic expressions for Classic Engines. For information on how to specify values for tests created with Engines 3.0, see chapter "Specify values". |
Tosca Commander provides on-screen descriptions for all dynamic values in Tricentis Tosca.
To see them, type { into the Value field. This automatically opens the expression dropdown menu.
Random numbers
You can use random numbers for entering values.
Syntax: |
{RND[<Number of Digits>]} A number between 1 and 32000 can be entered as the number of digits. |
In this example, a random twelve-digit number is input:
Random numbers |
Random text
You can enter random text as a test value.
Syntax: |
{RANDOMTEXT[<Number of characters>]} |
In this example, a random text with 12 characters is input:
Random text |
Random character strings
You can use a random character string as value. This consists of 16 random numbers and characters.
Syntax: |
{CTMSTMP} Example of a result: 5l8o8de07smz00jg |
Intervals
You can define value intervals for specific values in order to verify values. All values within this interval are valid.
Syntax: |
<Number>{INT[+/-<Interval>]} |
The value specified by <Number> defines the number to be used as a starting point for calculating the interval. The upper and lower limit of intervals are defined under <Interval>.
The DataType must be set to Numeric.
123,6{INT[+/-5]} All values from 118.6 to 128.6 are valid.
Intervals |
Calculations
Microsoft® Excel must be installed in order to use the CALC function.
Calculations are carried out using the following syntax:
Syntax: |
{CALC[<Operand 1><Operator><Operand 2>..<Operator><Operand n>]} |
The formula to be entered into an Excel cell is specified in square brackets. The four basic types of calculation (+, -, *, /) are supported as operators. The operators are processed according to the PEMDAS rule, i.e. multiplications and divisions are calculated before additions and subtractions, and can be modified with brackets.
If numbers with a thousands comma (digit grouping) are used, these must be put in quotation marks (e.g. “1,234.56”).
How functions and number formats are denoted depends on the defined localization. The setting Engine Calculator must be enabled in order to use Microsoft® Excel settings. |
In this example, the value 10 is transferred to the test object as a result of the calculation 5 + 5.
Calculation |
Sample Function - FIXED
The function FIXED allows numbers to be fixed as values with a set number of decimal places. This function is also used for calculations which result in numbers with more than eleven digits.
Syntax: |
{CALC[Fixed(<Operand 1><Operator><Operand 2>..<Operator><Operand n>,<Number>,<No_dots>)]} |
The value specified by <Number> defines the fixed number of decimal places to which the number is rounded. If a whole number (without any decimal places) is to be formatted, the value 0 must be entered.
The command <No_dots> is optional and defines the character format. Possible values are True or False.
-
True: No thousands comma
-
False: Thousands comma
-
Not specified: see setting Engine Calculator
In this example, the value of the division sum 5000/3 should be written to an input field. The result should be rounded up or down to a decimal place. When the value True is entered, the thousands comma is excluded. The result of the calculation is 1666.7. This example relates to the English Excel version with the active setting Engine Calculator.
Calculation For a German Excel version, the syntax for this example is as follows:{CALC[FEST(5000/3;1;Wahr)]}. |
Date expressions
In Tosca, we use the basic date as initial value for dynamic date expressions. There are several expressions for this which are defined in differing ways depending on the system settings. You can modify the date format in the system settings at Start->Control Panel->Regional and Language Options, in the Formats tab.
Example of short date format in the system settings: TextDate (short): DD.MM.YYYY |
Valid values for the basic date
Dynamic date expressions are specified in curly brackets.
Formats for the expressions DAY, MONTH, YEAR or DATE can be altered with a prefix.
Prefix |
Description |
Example |
---|---|---|
{LDATE},{LDAY},{LMONTH},{LYEAR} |
Date, day, month, and year according to the current system settings. |
{LDAY} = Monday |
{NDAY},{NMONTH},{NYEAR} |
Day, month and year are always entered in double figures. Single digit results are displayed with a zero before them. |
{NYEAR} = 13 |
{ADAY},{AMONTH} |
Shows the first three letters of a month name. |
{AMONTH} = Dec |
Modify basic date
The basic date can be changed by any number of increments.
Syntax: |
{<Basic date>[<Increment 1>] … [<Increment n>]} |
Reference date
To specify date values which differ from the current date (basic date), a reference date can be specified as an increment.
Syntax: |
<Basic date>[<Reference date>] All values from Illustration "Basic date - possible values" can be used as the basic date. A random date can be entered as the reference date which should be used for the calculation. A buffer can also be read out. |
In this example, a three character month name is written to the input field using the reference date 11.Aug 2007 Syntax: {AMONTH[11.Aug 2007]} Result: Aug
Example - dynamic date |
The date value 10.12.2013 is written to the buffer Date. The day is read from this date value and entered into an input field. Syntax: {Day[{B[Date]}]} Result: 10
Reference date - Day |
Adding or subtracting increments
Days, months or years can be added or subtracted from the basic date. Any number of these increments can be added to the syntax.
The syntax of an increment is structured as follows:
Syntax: |
[<Operator><Number><Unit>] Operator: + or - Number: Number which is added or subtracted Unit:
Units must be entered sequentially in descending order, e.g. J, M, T. |
The current date in this example is 15/04/2010. In the following table, dynamic date values are created using this date as a starting point. The option English (Great Britain) in the Format tab must be selected in the Microsoft Windows® System settings under Start->Control Panel->Regional and Language Options.
|
National holidays
To calculate working days, Tosca requires information on the national holidays in the particular country. There are set and changeable public holidays.
The changeable (Christian) holidays are set on the date of Easter Sunday. This date can be determined until the year 8202 by using a formula.
The Gregorian calendar is the standard for calculating public holidays. The holiday rule currently valid in Austria is used as a basic setting. |
National holidays can be freely defined in the Settings dialog (see chapter "Settings - Special Dates").
Time expressions
Expressions for the current date and time can be used. The date and time format matches the definition in the system settings under Start->Control Panel->Regional and Language Options - Formats tab.
The following expressions can be used:
Expression |
Description |
Example |
---|---|---|
{Time} or {Zeit} |
The current time of day in short format. |
11:28 |
{Hour} or {Stunde} |
The current hour. |
12 |
{Minute} |
The current minute. |
41 |
{Second} or {Sekunde} |
The current second. |
21 |
{RNDTIME} |
Random time in short format. |
06:51 |
The format can be changed for the expressions {Hour}, {Minute}, {Second} or {Time} by using a prefix.
Prefix |
Description |
Example |
---|---|---|
N |
Hours, minutes and seconds are always outputted as two-digit numbers. Results with one-digit receive a leading 0 digit. |
{NMinute} = 07 |
L |
The current time is outputted as an extended time format. |
{LTime} = 11:28:57 |
Translating values
If dialogs are available in different languages, the different values can be translated. The basis for the translation is a simple Excel worksheet, where a column is created for each required language.
This function must be activated via the setting Enable Translation Mode.
Structure in Excel
-
Specify the required languages in the first line of each column. You can use any number of columns (languages).
-
In the following lines, enter the values in the corresponding languages.
Example for an Excel worksheet
-
Configure the translation settings in the Settingsdialog (see chapter "Settings - Translation").
The names of the languages must match the column names in the Excel worksheet.
Usage in TestCases
To use a value from the Excel worksheet, the following syntax is used:
Syntax: |
{T[<Value>]} The expression to be translated is specified as <Value>. |
Translation of values in a TestCase
Expressions with more than one translation
If there are expressions with more than one possible translation, the correct translation can be selected using an additional column in the Excel worksheet. Define the name of the new column in the Settings dialog as the value of the setting Message Column (see chapter "Settings - Translation").
Numerical values are used in the Excel worksheet for the new column.
Use the following syntax in the TestCase to read the value out:
Syntax: |
{T[<Value>;<Message Column>]} or {T[;<Message Column>]} The required value of the Message Column is specified under <Message Column>. |
This example involves the values in the Excel worksheet in Illustration "Example: Translation worksheet". German is set as the Source Language and French as the Target Language. Example 1
Example Translation Tosca
Example Translation Result, Target Language French Example 2
Example Translation using the Message Column
Translation result: using the parameter Number |
Translating window captions
The window title of a test object is used for identification purposes in most cases. This title often relates to languages due to the Internationalization in software development (I18N). Window titles can be translated in order to make automated steering possible.
Procedure
The function described in chapter "Translating values" is used for the translation. The individual steps are described in more detail in this chapter.
-
The source language that was used for creating the Module must be defined in the setting Source Language.
-
The Excel worksheet containing the values for the translation must be created. The file path and the name of the Excel worksheet must be defined via the following settings: Translation Workbook and Translation Sheet.
Window caption translation - Excel sample table
-
The chosen target language, used for the translation, must be defined with the TargetLanguage setting.
-
The dynamic expression {T[<Value>]} is used in the ObjectMap of the Module as the value of the TechnicalId parameter. The translated value is obtained using this syntax.
The setting Dynamic Translate must be enabled in order to use dynamic values in the ObjectMap.
Translation expression in the ObjectMap of a Module
We recommend deactivating the translation errors display option when translating window titles (see setting Show translation errors). |
Translating properties
There are several differing commands available for verifying control properties in various engines. The various commands can be translated in order to facilitate automated steering.
Procedure
The function described in chapter "Translating values" is used for the translation. The individual steps are described in more detail in this chapter.
-
The technology which the Module is created with must be defined using the setting Source Language (column names).
-
The Excel worksheet containing the values for the translation must be created. The file path and name of the Excel worksheet must be defined via the settings Translation Workbook and Translation Sheet.
Translation of properties - Excel sample table
-
The chosen target language, which is used for the translation, must be defined using the setting TargetLanguage (column names).
-
The setting TranslateVerificationView must be enabled so that the command from the translation table is interpreted correctly.
-
In the TestCase, the command from the Excel worksheet is read using the dynamic expression {T[<Value>]}.
Translation expression in the TestCase
Transferring data from the settings
All values which are stored in the Settings dialog (see chapter "Settings Dialog") can be read dynamically and used during test execution.
Syntax: |
{S[<Path>]} |
The path of every setting can be copied to the clipboard in the Settings dialog (see chapter "Copy Path to Clipboard").
{S[Engine.Current Test User]} This example provides the value of the setting Current Test User, for instance <Windows Logon> (see chapter "Current Test User"). |
Graphical View
Tosca Commander provides a graphical view for dynamic expressions. This makes reading and understanding the syntax easier, especially for embedded expressions.
The graphical view displays expressions with various shapes and colors:
Visualizing dynamic expressions in Tosca Commander
To edit an expression, double-click it.
Tricentis Tosca does not visualize expressions that contain erroneous syntax.
This format is enabled by default. You can disable it by clicking on the View menu and selecting TestCase->Show Dynamic Expressions (graphical view).
You can also disable visualization by deselecting the checkbox in the Options dialog at Project->Options->View->TestCase->Show dynamic expressions (grapical view).