6.11. Flex Object API

[Important]Flex-specific

The Flex Object API is only available for the Squish for Web editions.

Squish provides a comprehensive API for Flex objects, which is documented here in its entirety.

[Note]Flex Object API Function Parameters

In all the functions listed below that take an objectOrName argument, the argument can be a reference to an object or the name of an object as a string.

Some of the Flex Object API functions can take a modifierState argument which indicates which special keys are pressed at the time of a mouse click. And some of the functions can also take a button argument which indicates which mouse button was clicked.

The modifierState can be one or more of the following: Modifier.None, Modifier.Alt, Modifier.Control, Modifier.Shift. If more than one is used they must be OR-d together, for example, Modifier.Alt|Modifier.Shift. The form shown here works e.g., Modifier::Control, and for Tcl use the enum function, e.g., enum Modifier Control.

The mouseButton can be any one of: MouseButton.None, MouseButton.Wheel, MouseButton.LeftButton, MouseButton.MiddleButton, MouseButton.RightButton.

The form shown above works for Python and JavaScript.

For Perl use this: MouseButton::LeftButton, etc.

For Ruby use this: MouseButton::LEFT_BUTTON, etc.

For Tcl use this: enum MouseButton LeftButton, etc.

Here are some quick links to the Flex Object API's functions:

chooseDate(objectOrName, dateString);

This function can be used to set the date in the objectOrName datefield widget. The dateString has to be a string of the form "2013/04/27", with the first four digits denoting the year, the next two digits denoting the month and the last two digits denoting the day. For months and days smaller than 10 add a leading zero to the number. The 3 values need to be separated as indicated above using forward slashes.

clickButton(objectOrName);

This function clicks the objectOrName widget which should be the name of a button or a reference to a button object.

clickItem(objectOrName, itemText);

This function clicks the objectOrName widget's item that has the specified itemText. This will work for any Combobox widget.

collapse(objectOrName);

If the objectOrName is a tree or tree item, it is collapsed so that none of its child items (if it has any) are visible. (See also expand.)

doubleClick(objectOrName);

doubleClick(objectOrName, mouseButton);

doubleClick(objectOrName, mouseButton, modifierState);

doubleClick(objectOrName, x, y, mouseButton);

doubleClick(objectOrName, x, y, mouseButton, modifierState);

This function double-clicks the objectOrName widget.

By default the widget is double-clicked in the middle, but this can be changed by passing widget-relative coordinates, x and y. By default MouseButton.LeftButton is used, but this can be changed by specifying the optional mouseButton argument. Similarly a default modifier state of Modifier.None is used, but this can be changed by specifying the modifierState argument. Note that to specify the button, the coordinates must also be specified; and to specify the modifier state, the coordinates and the button must also be specified. See Flex Object API Function Parameters for which values are valid for the mouseButton argument and for the modifierState argument.

expand(objectOrName);

If the objectOrName is a tree or tree item, it is expanded to show its child items (if it has any). (See also collapse.)

installEventHandler(eventName, handlerFunctionNameOrReference);

This function installs a global event handler. The script function named or referenced in handlerFunctionNameOrReference, will be called when an event of the eventName type occurs.

The eventName can be the name of any of the following event types:

The function named in handlerFunctionName is called with a single argument—the object on which the event occurred.

For examples see How to Use Event Handlers (Section 5.10).

[Important]The AUT Must be Running

The installEventHandler function will only work if it is called after the AUT has been started (e.g., using the startApplication function).

mouseClick(objectOrName);

mouseClick(objectOrName, mouseButton);

mouseClick(objectOrName, mouseButton, modifierState);

mouseClick(objectOrName, x, y, mouseButton);

mouseClick(objectOrName, x, y, mouseButton, modifierState);

This function clicks the mouse on the specified objectOrName widget.

If only the objectOrName is specified, then the object is clicked in the middle by the MouseButton.LeftButton. All the other usages require the mouseButton to be specified, optionally preceded by by object-relative coordinates, x and y which say where the click takes place, and optionally followed by a modifierState (which defaults to Modifier.None if not specified).

See Flex Object API Function Parameters for which values are valid for the mouseButton argument and for the modifierState argument.

mousePress();

mousePress(mouseButton);

mousePress(mouseButton, modifierState);

mousePress(x, y, mouseButton);

mousePress(x, y, mouseButton, modifierState);

mousePress(objectOrName);

mousePress(objectOrName, mouseButton);

mousePress(objectOrName, mouseButton, modifierState);

mousePress(objectOrName, x, y, mouseButton);

mousePress(objectOrName, x, y, mouseButton, modifierState);

This function performs a mouse press. All the parameters are optional excepting that either both or neither of the coordinates must be present.

If x and y coordinates are given, the press takes place at those coordinates, either relative to the objectOrName object if one is specified, or relative to the current screen otherwise. If no coordinates are given the press takes place on the middle of the objectOrName object if one is specified, or wherever the mouse happens to be otherwise.

By default MouseButton.LeftButton is used, but this can be changed by specifying the optional mouseButton argument. Similarly a default modifier state of no modifiers is used, but this can be changed by specifying the modifierState argument. See Flex Object API Function Parameters for which values are valid for the mouseButton argument and for the modifierState argument.

mouseRelease();

mouseRelease(mouseButton);

mouseRelease(mouseButton, modifierState);

mouseRelease(x, y, mouseButton);

mouseRelease(x, y, mouseButton, modifierState);

mouseRelease(objectOrName);

mouseRelease(objectOrName, mouseButton);

mouseRelease(objectOrName, mouseButton, modifierState);

mouseRelease(objectOrName, x, y, mouseButton);

mouseRelease(objectOrName, x, y, mouseButton, modifierState);

This function performs a mouse release. All the parameters are optional excepting that either both or neither of the coordinates must be present.

If x and y coordinates are given, the release takes place at those coordinates, either relative to the objectOrName object if one is specified, or relative to the current screen otherwise. If no coordinates are given the release takes place on the middle of the objectOrName object if one is specified, or wherever the mouse happens to be otherwise.

By default MouseButton.LeftButton is used, but this can be changed by specifying the optional mouseButton argument. Similarly a default modifier state of no modifiers is used, but this can be changed by specifying the modifierState argument. See Flex Object API Function Parameters for which values are valid for the mouseButton argument and for the modifierState argument.

Object nativeObject

Squish automatically adds a property called nativeObject to every Flex Object's list of properties. The native object provides access to all the underlying object's methods and properties.

For examples of how to use the nativeObject see How to Use the nativeObject Property (Section 5.5.2).

scrollTo(objectOrName, integer);

This function sets the scroll position of the, objectOrName scrollbar widget to the given integer value.

This function can be used to scroll a scrollbar. The given value is in logical units and not pixels.

setValue(objectOrName, integer);

This function sets the value of the, objectOrName spinbox widget to the given integer value.

This function can be used to set the numeric value in a spinbox.

type(objectOrName, text);

This function types the specified text (as if the user had used the keyboard) into the objectOrName editable widget. If the text is surrounded by angle brackets (<>), it is interpreted as a key combination, e.g "<Ctrl+Return>". The input is case-sensitive, so type(object, "R") is different from type(object, "r"). (For a list of the supported special keys see the nativeType function's documentation.)

uninstallEventHandler(eventName, handlerFunctionNameOrReference);

This function uninstalls an event handler that has been previously installed using installEventHandler.