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.

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.

Basic date - possible values

Expression

Description

Example

{DATE} or {DATUM}

Full date.

30.12.2013

{DAY} or {TAG}

Current day.

30

{MONTH} or {MONAT}

Current month.

12

{YEAR} or {JAHR}

Current year (two-digit).

13

{RNDDATE[first year, last year]}

Random date within the specified year, e.g. {RNDDATE[2002, 2013]}. The result is transferred as a complete date.

08.10.2006

{TMSTMP}

Time stamp: current day, current month, current time and random year (accuracy in miliseconds).

30.12.2743 15:03:02.300007

{MONTHFIRST} or {MONATSERSTER}

First day of the current month as a complete date.

01.12.2013

{MONTHLAST} or {MONATSLETZTER}

Last day of the current month as a complete date.

31.12.2013

{QUARTERFIRST}

First day of the current quarter as a complete date.

01.10.2013

{TRIMESTERFIRST}

First day of the current trimester as a complete date.

01.09.2013

{HYEARFIRST}

First day of the current half year as a complete date.

01.07.2013

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:

  • D or T for days

  • W or A for working days

  • M for months

  • Y or J for years

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.

Example - dynamic date expressions

Syntax

Result

{Ldate}

Thursday, 15 April 2010

{Date+1M+1D}

16/05/2010

{LDay}

Thursday

{LMonthfirst+35D}

Thursday, 06 May 2010

{LMonth+1M}

May

{Date[15/04/2010]+3D}

18/04/2010

{LMonthfirst[15/04/2010]+3D}

Sunday, 04 April 2010

{Quarterfirst[{Date[15/04/2010]}]+3M}

01/07/2010 (The first day of the next quarter)

{Trimesterfirst[{Date[15/04/2010]}]+4M}

01/05/2010 (The first day of the next trimester)

{HYearfirst[{Date[15/04/2010]}]+6M}

01/07/2010 (The first day of the next half year)

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

  1. Specify the required languages in the first line of each column. You can use any number of columns (languages).

  2. In the following lines, enter the values in the corresponding languages.

Example for an Excel worksheet

  1. 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.

Example: Translation worksheet

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

  1. The word Auto should be translated and written to the input field Make of the test object, along with the value Test.

Example Translation Tosca

  1. The value Voiture Test is written to the input field.

Example Translation Result, Target Language French

Example 2

  1. The value Nummer appears several times in the translation table. The column MessageNumber is used to translate the correct value.

Example Translation using the Message Column

  1. The values Nombre Test and Chiffre Test are transferred to the application.

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.

  1. The source language that was used for creating the Module must be defined in the setting Source Language.

  2. 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

  1. The chosen target language, used for the translation, must be defined with the TargetLanguage setting.

  2. 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.

  1. The technology which the Module is created with must be defined using the setting Source Language (column names).

  2. 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

  1. The chosen target language, which is used for the translation, must be defined using the setting TargetLanguage (column names).

  2. The setting TranslateVerificationView must be enabled so that the command from the translation table is interpreted correctly.

  3. 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).