The 4Test language
4Test is an object-oriented fourth-generation language (4GL).
Active and Enabled Statuses
SilkTest Classic provides two options to help you specify whether to raise an exception when particular methods are called on windows:
OPT_VERIFY_ACTIVE
OPT_VERIFY_ENABLED
Calling Methods and Functions
Method Calls
A method is a routine that applies to a particular class of objects.
You can call methods for a window that has not previously been declared using a special identifier for dynamic instantiation. The syntax varies depending on whether you use INC files. When you record a test case with the Open Agent, SilkTest Classic creates locator keywords in an INC file to create scripts that use dynamic object recognition and window declarations. You can also manually create test cases that use dynamic object recognition without an INC file. Dynamic object recognition uses a Find or FindAll function and an XPath query to locate the objects that you want to test. No INC file, window declarations, or tags are required.
Use the following syntax with INC files:
calss(“tag”).class(“tag”). …
The following example calls a method on a dynamic instantiation of Find:
MainWin("Text Editor -*").DialogBox("Find").SetActive ()
Use the following syntax without INC files:
Findclass name(locator). ...The following example calls a method on a dynamic instantiation of Find:
FindMainWin("@caption=’Text Editor -*’").FindDialogBox("Login").
FindTextField("@priorlabel=’password’").TypeKeys("top secret")
Function Calls
A function is a routine that does not pertain to any particular object.
Use NULL for arguments that need no value specified. For example, the following code adds one hour to the Datetime value in newDateTime.
newDateTime = AddDateTime (datetime, NULL,1)
(* The AddDateTime function syntax: newDT = AddDateTime(Datetime[, iDays, iHours, iMins, iSecs, iMsecs])
Passing the Name of the Function or Method to a Test
You can use the ArgListCall keyword to pass the name of the function or method, along with its arguments, at runtime in data-driven tests.
Comments in 4Test Files
You can embed single-line comments in all 4Test files: Any characters following // in a line are considered comments.
Note: Shift+Enter, which wraps lines of code, is not available for comments. You must insert double-slashes on the next line for run-over comments.
Comments within functions and test cases must be within the scope of the function or test case. If a comment is outdented beyond the scope of the function or test case, the compiler assumes that the function or test case has ended.
Built-in Constants
The following constants are built into the 4Test language:
TRUE
FALSE
In addition to these built-in constants, 4Test predefines two other kinds of constant values:
Exception values
Agent options
Overview of File Handles and Remote File Input and Output
Note: SYS_ functions are not designed for local access. Non SYS_ functions are not designed for remote access.
Reading from a File
4Test recognizes that it has reached the end of a file (EOF) by no longer reading that file – in other words, by receiving a null string. It does not read any special character at the EOF.
For SilkTest Classic, EOF is indicated by a FALSE bDidRead return and a null string is indicated by a TRUE bDidRead return and a null string.
This applies to FileReadLine, FileReadValue, SYS_FileReadLine, and SYS_FileReadValue.
Tips for Using the Remote File Functions
The scope of the local files (FileOpen() or IniFileOpen()) is from the start of a script to the end of the script. A script is either the individual test in a TestPlan or the run of a main (implicit or explicit) which can cross multi testCase. The scope of remote files (SYS_FileOpen() or SYS_IniFileOpen()) is from AGENT connect to AGENT disconnect. Most of the time, the default of remote is the start of a TestCase to the exit of the TestCase. The default can be overwritten by the use of the connect and disconnect 4Test function.
Writing to a File
The File functions that control writing to a file do not test your accessibility to a file. This means that you cannot write information to a file that has been opened in read only mode with FileOpen(). The function will successfully return, but no information is actually written to the file. No error message indicates this.
This applies to FileWriteLine, FileWriteValue, SYS_FileWriteLine, and SYS_FileWriteValue.
Flow-Of-control Statements
The following table summarizes the flow-of-control statements in the 4Test language.
To |
Use One of these 4Test Statements |
Repeat commands in a loop |
for each Executes a statement or group of statements once for each element in a list. for Executes a loop once for each increment of a counter. while Executes a loop until a test condition (boolean expression) is false. |
Conditionally execute a command |
if Executes a statement block based on the value of a boolean expression. select Executes one case from a group of cases. switch Executes one of the statements that follow, depending on the value of an expression. |
Handle or raise exceptions |
do...except Handles an exception rather than having it halt the test case. raise Raises a user-defined exception. reraise Re-raises an exception you are handling yourself within a do...except statement. |
Transfer flow of control |
break Transfers control of the script out of the innermost nested for, for each, while, switch, or select statement. continue Begins the next iteration of a for, for each, or while statement without completing the current iteration. exit Ends execution of the current script. goto Transfers control to the statement prefixed with the specified label. return Returns control back to the calling function, optionally passing back a return value.
|
Numeric Representation Conventions
Binary
Each number has a prefix of 0b (zero, lowercase B), for example 0b10110111.
Decimal
A number without a prefix, for example, 1776.
Hexadecimal
Each number has a prefix of 0x (zero, lowercase letter X), with the letters A through F representing the numbers above 9, for example 0x03CF 07FFF and 0x0010.
Embedded spaces in long numbers are for ease of reading and are ignored.
Properties
The properties are listed with the description of each class in the help. The descriptions use the internal names, that is, the names that begin with the $ character. For example, $Location is a property of the HtmlLink class.
The internal names are provided in the class descriptions because they are the names that are used by the verification system.
But there are also 4Test names for each of these properties. These names use Hungarian notation, that is, they are prefixed with an abbreviation for the data type. The 4Test names are shown for the classes in the Library browser.
Using the Properties
You can retrieve the values of all properties directly in a script using dot notation as long as you use the 4Test name, not the internal name. Using the GMO Web application’s home page, for example:
INTEGER iSize
iSize = GMO.WelcomeText.iFontSize
Print (iSize)
When using the internal name, use the GetProperty, GetTextProp, or GetItemProp method, whichever is appropriate. For example:
INTEGER iSize
iSize = GMO.WelcomeText.GetProperty("$FontSize")
Print (iSize)
Variable Number of Arguments
You specify a variable number of function arguments as follows:
varargs [of data-type] list-id
Variable |
Description |
Data-type |
The data type of the variable arguments. |
List-id |
An identifier specifying the name of the list variable that holds the variable arguments. |
Example 1:
The ProcName function declaration below specifies that the second argument can be NULL and that the third argument is optional. The test case that follows calls ProcName.
ProcName(BOOLEAN b, STRING sName NULL, INTEGER iStart optional)
Example 2:
The function MyFunc1 uses different argument pass modes. The test case calls MyFunc1.
BOOLEAN MyFunc1(STRING s, out INTEGER iNew, inout INTEGER iChange)
Example 3:
The function MyFunc2 is declared to take a variable number of arguments.
MyFunc2(INTEGER iTestNum, varargs OF STRING lsArg)
Reserved Words
Case is significant in keywords, so "exit" is a reserved word, but "EXIT" and "Exit" are not.
Unlike keywords, type names are not case-sensitive, so "CHAR" and "char" are both reserved words.
The boolean constants TRUE and FALSE are also reserved by the compiler and are case insensitive.
Identifier Naming Rules
Identifiers conform to these naming rules:
They are case-sensitive. That is, "myvar" and "MyVar" are not the same.
They begin with an alphabetic character or an underscore (_).
They include any combination of alphabetic characters, numerals, and underscore characters. They can contain single-byte international characters, such as é and ñ.
Wildcards
The * character matches zero or more characters.
The ? character matches exactly one character.
Where You Can Use Wildcards
Some of the situations where you can specify wildcards include:
- Tags.
- Search text in the FindCell method.
- Identifier for items in combo boxes, list boxes, radio lists, and so on.
- In the entries in the [ClassList] section of javaex.ini. Wildcards are useful for exposing (or ignoring) all classes in a package.
- When ignoring or exposing Java classes in a package.
Key Names
Rules for Key Names
Rule |
Description |
Example |
Angle brackets in names |
If a key name is more than one character in length, enclose it in angle brackets. |
“<Enter>” |
|
If it is only one character long, you can specify it with or without angle brackets. |
“Z” |
Case sensitivity |
Case is significant only in one-character key names. |
The following are equivalent:
The following are not equivalent:
|
Combining keystrokes |
You can combine any number of keystrokes in a single string. |
“<Alt-F>S<Enter>” |
Groups of keys |
Include groups of keys that you want pressed simultaneously in the same set of angle brackets, and separate the keys with minus signs (-) or plus signs (+) depending on the Agent that you are using. Note: The Classic Agent only supports minus signs (-) as a delimiter between key names while the Open Agent supports plus and minus signs. |
"<Ctrl-Shift-F10>" |
Partial Key names |
Partial key names are invalid. |
|
Repeated keys |
Specify repeat counts by following the key name with the integer repeat count. |
"<Tab 2>"
"<X 15>" |
Using Shift and Option keys |
The Shift key is not necessary when you are specifying a single alphabetic character. On Windows you must specify the full compose sequences for accented characters. |
The following are equivalent”
|
Syntax Conventions
Variable Prefixes
Variables are specified in Hungarian notation, that is, prefixed with an abbreviation for the data type. The data types and abbreviations are as follows: anytype (a), agentoption (ao), boolean (b), dataclass (dc), datatype (dt), guitype (gt), handle (h), integer (I), number (n), point (p), real ®), rect (re), semaphore (se), string (s), string or integer (si), sbrange (sr), textpos (tp), textrange (tr), window (w), winclass (wc), winstate (ws) and wndtag (wt). Any of these types can be a list, such as list of string (ls) or list of window (lw). Any of these types can also be an array, such as array of anytype (aa) or array of string or integer (asi).