window Declaration

Action

Uniquely identifies an object in the graphical user interface.

Note: Window declarations must appear outside of any function.

Syntax

[scope] window win-class win-id
statements
Variable Description
scope Optional: Either public (the default) or private. Private declarations are available only in the file in which they occur. Public declarations can be accessed from other files by means of a use statement.
win-class An identifier specifying the name of a 4Test window class (defined in winclass.inc) or a user-defined window class.
win-id An identifier specifying the name you want to use to refer to the window.
statements The statements that make up the window declaration. These include a required tag statement, and optional variable declarations, parent statements, declarations for child windows, method definitions, and property definitions.

Notes

  • Window declarations uniquely identify each window in a graphical user interface. You need not write window declarations yourself, because Silk Test Classic generates them for you. However, you are free to make changes to the window declarations that Silk Test Classic generates.

  • Commands you use in a 4Test script to manipulate GUI objects are of the form:
    TextEditor.File.New.Pick ()
  • To find the correct object to Pick, Silk Test Classic must be able to construct a unique path to the object at runtime, by using information contained in the window declarations for the application.

Components of a Window Declaration

A window declaration uniquely identifies an object by providing this information:

  • The class of the object.

  • The identifier of the object; this is the name you use to refer to the object in your 4Test scripts.

  • The tag of the object; this is the name which 4Test uses internally to refer to the object.

  • Optional: The parent window of the window.

  • Optional: The child windows of the window.

  • Optional: The methods and properties of the window. They are unique to the window; that is, they are not inherited from the class.

Declaring Child Windows

You declare a child window by writing its declaration as one of the statements inside the parent window's declaration. A child window declaration has this form:

[gui-specifier] class-id window-id
statements
Variable Description
gui-specifier Optional: Specifies the GUIs that the child window applies to. See "GUI specifiers" below. If omitted, the child window applies to all GUIs.
class-id An identifier specifying the name of a 4Test window class, which is defined in winclass.inc, or a user-defined window class.
window-id An identifier specifying the name of the child window.
statements The statements that define the child window. These include a required tag statement, and optional variable declarations, method definitions, and property definitions

You cannot use a parent statement within a the declaration of a child window. The parentage of the window is implicitly known to Silk Test Classic because the declaration is physically contained within the declaration for the parent window.

Declaring Methods and Properties

You can declare methods and properties for a new window within the window declaration or within its window class declaration. See Method declaration and the property declaration.

GUI Specifiers

You have the option to use a GUI specifier with any statement in a window declaration. The GUI specifier indicates that the specified statement applies only when the application is running under the indicated GUI or GUIs.

The syntax for GUI specifiers is of the following form:
[ [gui-type [, gui-type]]| [! gui-type]]
Variable Description
gui-type A GUI type. If you do not specify gui-type, the specified portion of the window declaration applies to all GUIs.
For example, the following are two mutually-exclusive ways to specify GUI types for a tag statement:
  • The tag statement applies to one or more GUIs, separated by commas:
    msw2003, mswnt tag "my-tag-string"
  • The tag statement applies to all but one GUI:
    ! mswnt tag "my-tag-string"
Note: The reference entry for the GUITYPE data type lists the available GUI types.

Declaring Variables

You can place variable declarations inside window declarations. The variables can be used anywhere an expression is allowed.

The syntax of a variable declaration in a window declaration is of the following form:
[gui-specifier] data-type var-id [ = expr ] [, var-id [ = expr ]]...
Variable Description
gui-specifier Optional: Specifies the GUIs that the variable declaration applies to. For additional information, see GUITYPE Data Type. If omitted, the declaration applies to all GUIs.
data-type The data type.
var-id An identifier that refers to the variable.
expr An optional expression that evaluates to the initial value you want to give the variable. The value must be compatible with the type of the variable. You must initialize the variable either in the window declaration or before you use it in your script. If you try to reference the value of a variable before its value is set, 4Test raises an exception.

The following example shows how you can declare variables within a window declaration:

[-] window DialogBox Find
	[ ] INTEGER x = 0
	[ ] BOOLEAN bDone = FALSE, bFound = FALSE
	[ ] // ...

You reference the value of the variables of a window by using the member of operator (.). For example, here are two ways of referencing the window variable x of the Find dialog box:

Find.x = 5 // Assigns INTEGER value 5 to variable x
foo = Find.x // Assigns to foo the value of x

Example

[-] window DialogBox Find
	[ ] tag "Find"
	[ ] parent TextEditor
	[ ] WINDOW wInvoke = TextEditor.Search.Find
	[-] StaticText FindWhatText
		[ ] tag "Find What:"
	[-] TextField FindWhat
		[ ] tag "Find What:"
	[-] CheckBox CaseSensitive
		[ ] tag "Case sensitive"
	[-] StaticText DirectionText
		[ ] tag "Direction"
	[-] PushButton FindNext
		[ ] tag "Find Next"
	[-] PushButton Cancel
		[ ] tag "Cancel"
	[-] RadioList Direction
		[ ] tag "Direction"