![]() | Java-specific |
|---|---|
The Java Convenience API is only available for the Squish for Java™ editions. |
Here are some quick links to the Java Convenience API's functions:
This function activates the JFace action object with the
objectName symbolic or real name.
![]() | SWT-specific |
|---|---|
This function is only available when testing Java/SWT applications. |
This function activates the menu item with the specified
itemText in the objectName
menu, context menu, or menu bar.
This function invisibly invokes the platform's
native “choose color” dialog. The
objectOrName must always be the application's
“SWT” object (":SWT"). The color parameters
must all be integers each in the range 0 to 255; they are used to
specify the color that is chosen using the dialog.
![]() | SWT-specific |
|---|---|
This function is only available when testing Java/SWT applications. |
This function invisibly invokes the platform's
native “choose directory” dialog. The
objectOrName must always be the application's
“SWT” object (":SWT"). The
path is a string which specifies the directory
chosen using the dialog.
![]() | SWT-specific |
|---|---|
This function is only available when testing Java/SWT applications. |
This function invisibly invokes the platform's
native “choose file” dialog. The
objectOrName must always be the application's
“SWT” object (":SWT"). The
filename is a string (that may include a path)
which specifies the filename chosen using the dialog.
![]() | SWT-specific |
|---|---|
This function is only available when testing Java/SWT applications. |
This function clicks the specified objectOrName
button.
This function clicks the mouse on the item with the specified
itemText inside the given
objectOrName view widget. The click is made at
position x and y (in the
itemText item's coordinates). The
button and modifierState
parameters are optional; if they are not specified, the click is made
with the left mouse button and using a null keyboard modifier state. If
the button and
modifierState are given, the click is made with
the specified button and keyboard modifier state.
Supported view widgets are List, Combo, and ToolBar for the SWT toolkit, and JList, JTable, JTree, List, and Choice for the AWT/Swing toolkit.
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function clicks on the tab that has the specified
tabText on the
objectOrName tab widget. The
x, y,
modifierState, and button
parameters are optional. If the optional parameters are not given, the
click is made with the left mouse button in the middle of the tab and
with a null keyboard modifier state. And if all the parameters are
given, this function clicks on the tab that has the specified
tabText on the
objectOrName tab widget at the position
x and y (in the
objectOrName tab widget's coordinates) using the
specified button and the
modifierState modifier.
![]() | Tab widget-specific |
|---|---|
This function can only be used with the
|
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function clicks on the expand/collapse (tree handle) for the item
that has the specified itemText on the
objectOrName tree widget. The supported tree
widgets are Tree for the SWT toolkit and JTree for
the AWT/Swing toolkit.
This function invisibly invokes the platform's
native “message box” dialog. The
objectOrName must always be the application's
“SWT” object (":SWT"). The
result is a constant which specifies the button
clicked inside the dialog. Valid values for the
result are
SWT.ABORT,
SWT.CANCEL,
SWT.IGNORE,
SWT.NO,
SWT.OK,
SWT.RETRY, and
SWT.YES.
![]() | SWT-specific |
|---|---|
This function is only available when testing Java/SWT applications. |
This function closes the objectName
Window (or Shell in SWT) as
if it was closed using its window system menu.
If the treeItem is a Swing JTree item or an SWT
Tree item (e.g., as returned by the waitForObjectItem function), it is collapsed so
that none of its child items (if it has any) are visible; otherwise an
exception is thrown. (See also expand.)
This function double-clicks the mouse on the
objectOrName widget at position
x and y (in the
objectOrName widget's coordinates) using the
specified button and with the
modifierState modifier state.
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function double-clicks the mouse on the item with the specified
itemText inside the given
objectOrName view widget. The double-click is
made at position x and y
(in the itemText item's coordinates). The
button and modifierState
parameters are optional; if they are not specified, the double-click is
made with the left mouse button and using a null keyboard modifier
state. If the button and
modifierState are given, the double-click is made
with the specified button and keyboard modifier state.
The supported view widgets are List, Combo, and ToolBar for the SWT toolkit, and JList, JTable, JTree, List, and Choice for the AWT/Swing toolkit.
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function performs a drag and drop operation. It begins by
initiating a drag on the source_objectOrName
widget starting at position sx and
sy (in the
source_objectOrName widget's coordinates), and
then it does the drop on the target_objectOrName
widget at position tx and
ty (in the
target_objectOrName widget's coordinates). The
operation is one of
DnD.DropNone, DnD.DropCopy,
DnD.DropMove, DnD.DropLink,
DnD.DropMoveTarget, or DnD.DropDefault.
This function performs a drag operation. It initiates a drag of the
specified objectOrName widget starting at
position x and y (in the
objectOrName widget's coordinates), using the
specified button and with the
modifierState modifier state. The
objectOrName widget is dragged by
dx pixels horizontally and by
dy pixels vertically.
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function performs a drop that was initiated by a call to the startDrag function. It does the drop on the
target_objectOrName widget at position
tx and ty (in the
target_objectOrName widget's coordinates). The
operation is one of
DnD.DropNone, DnD.DropCopy,
DnD.DropMove, DnD.DropLink,
DnD.DropMoveTarget, or
DnD.DropDefault.
If the treeItem is a Swing JTree item or an SWT
Tree item (e.g., as returned by the waitForObjectItem function), it is expanded to show
its child items (if it has any); otherwise an exception is thrown. (See
also collapse.)
This function takes a screenshot of the object
window (or widget) and returns it as an Image Object (Section 14.3.12).
See the waitForObject and findObject functions for how to get an object
reference to a window or widget.
This function installs a global event handler. The script function
named in handlerFunctionName (which must be passed
as a string, not as a function reference), 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 13.8).
![]() | The AUT Must be Running |
|---|---|
The |
This function clicks the mouse on the specified
objectOrName widget. The x
and y coordinates,
modifierState, and button
are all optional. If they are not specified the click is made in the
center of the widget with the left mouse button and using a null
keyboard modifier state. On the other hand, if the additional parameters
are given, the click is made at position x and
y (in the objectOrName
widget's coordinates) using the specified button
and with the modifierState modifier state.
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
mouseClick(objectOrName, x, y, clicks, modifierState, button);
This function clicks the mouse on the specified
objectOrName widget. The click is made at
position x and y (in the
objectOrName widget's coordinates) using the
specified button and with the
modifierState modifier state.
The clicks parameter is a count of the number of
clicks.
![]() | AWT/Swing-specific |
|---|---|
This function is specific to the AWT/Swing toolkit. The
|
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function performs a mouse drag operation. It initiates a mouse drag
of the specified objectOrName widget starting at
position x and y (in the
objectOrName widget's coordinates), using the
specified button and with the
modifierState modifier state. The
objectOrName widget is dragged by
dx pixels horizontally and by
dy pixels vertically.
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function moves the mouse to position x and
y relative to the top-left of the
objectOrName widget.
This function is useful if you want to trigger events that need the mouse to be at a particular position. For example, tooltips normally only appear when the mouse is over a certain area.
![]() | AWT/Swing-specific |
|---|---|
This function is specific to the AWT/Swing toolkit. (All SWT mouse clicks are always performed natively, so this function would be redundant for SWT.) |
This function clicks the mouse on the specified
objectOrName widget. The x
and y coordinates,
modifierState, and button
are all optional. If they are not specified the click is made in the
center of the widget with the left mouse button and using a null
keyboard modifier state. On the other hand, if the additional parameters
are given, the click is made at position x and
y (in the objectOrName
widget's coordinates) using the specified button
and with the modifierState modifier state.
See Java Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function initiates a drag on the
source_objectOrName widget starting at position
sx and sy (in the
source_objectOrName widget's coordinates).
The drop can be done using the dropOn
function.
Normally the dragAndDrop function is
used to perform a drag and drop in a single action. However, in some
situations it may be necessary to move the mouse over a different object
before the drop can take place. In such cases the test code would look
something like this:
startDrag(sourceObject, sx, sy) mouseMove(otherObject, x, y) dropOn(targetObject, tx, ty, operation)
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.)
In addition to the functions described above, test scripts can create native Java™ arrays, and insert and retrieve objects stored in the arrays. (For examples of use see Creating and Using JavaArrays (Section 13.4.5.2).)
This is a constructor function for creating native Java arrays. The
size specifies how many objects it may contain
(indexed from 0, so the last valid index is size
- 1). If the optional nameOfType
string is omitted, the function will return an array of type
java.lang.Object[; otherwise
the array will be of type
size].
The nameOfType[size]nameOfType is a string that can specify a
non-object type such as "int", or an object type such as
"java.lang.String".
JavaArrays have two functions and one property.
This function returns the object at position
index in the array. If the
index is out of bounds a catchable exception is
raised.
This read-only property holds the number of positions in the array. The
first item is at position 0 and the last item is at postion
javaArray.length - 1.
This function sets the item at position index in
the array to the given object. If the
index is out of bounds or if the
object is of an invalid type (e.g., a string when
the JavaArray holds integers), a catchable exception is raised.
In addition to the public Java™ class fields, and synthetic properties
generated from get* and
is* functions, Squish provides some additional
properties to make it easier to identify objects. (See Defining Property Sets (Section 15.10.2) for more details.)
| Property | Type | Description |
|---|---|---|
| aboveWidget | Object | Holds the object above this widget in the same logical parent Container or Composite. This should be used for objects that don't have a caption but often come with an accompanying widget. For example, edit boxes have no caption but might have a label above them. |
| arrowDirection | String | Holds the direction of SWT buttons that have the arrow style enabled. |
| buttonType | String | Holds the type of SWT buttons. This property is useful for identifying buttons with arrows. |
| caption | String | Holds the object's title, caption, or text, if this object typically has such text to display. |
| container | Object | Holds the parent Container or Composite that contains this object. These are typically tab pages or the menu bar. |
| firstItemText | String | Holds the first text to be found for child SWT ToolItem objects. If no text is found, then the tooltip text is used. This property's value could be the empty string if no text is found and no tooltip text is set. |
| leftWidget | Object | Holds the object to the left of this widget in the same logical parent Container or Composite. This should be used for objects that don't have a caption but often come with an accompanying widget. For example, edit boxes have no caption but often have a label on their left. |
| menuStyle | String | Holds the style of SWT menu—this indicates whether the menu is a menu bar, a popup menu, or a pull-down menu. |
| type | String | Holds the object's class name—but with any periods in the name replaced with underscores. |
| window | Object | Holds the top-level window that contains this object. |
Squish can work with all the standard AWT/SWT widgets out of the box. However, some custom widgets may represent their child components in a non-standard way, that is, not as AWT/SWT components. For example, a canvas might use normal Java objects to represent the items it displays. Or a Gantt diagram component might render its own contents, taking its data from a model. Squish's Java extension API makes it possible to extend Squish so that non-standard components in AWT and SWT applications can expose their APIs so that they become accessible to Squish and can therefore be accessed in test scripts just like any other component.
In order to tell Squish what functionality to expose, we introduce the concept of an Inspectable class. An Inspectable class is one that can respond to Squish's queries about objects of a particular type. For example, an Inspectable could handle canvas item types, and provide an API that can give Squish the canvas's bounds or its parent, or that returns all of its child items. The precise APIs are listed in the Inspectable interface; see Part I, “Java™ Extension API Reference”.
Once the Inspectables are registered, whenever Squish encounters an object, Squish queries each Inspectable to see if the Inspectable can handle the object (i.e., objects of the object's type). If one of the Inspectables reports that it recognizes the type as one it can handle, Squish uses that Inspectable's interface to interact with the object. This allows Squish to treat the object just like any of the standard AWT/SWT types that it supports out of the box—for example, Squish can query the Inspectable to see if the object has received a mouse click.
All the Inspectables for the types you want to Squish to be able to handle are placed together in a “wrapper” library. A clean way to do this is to put all the Inspectables classes in their own jar, although it is also possible to add them to the application's existing jar. The canvastest example shows how to put the Inspectables into their own jar.
Using the Java Extension API and a suitable wrapper, it is possible to support non-AWT/SWT components alongside standard AWT/SWT components so that Squish can:
To show how a wrapper to extend an existing AWT application works, we
will use the canvastest example which is
shipped together with Squish for Java. You can find the source code in
squish/examples/java/canvastest. (We could just as
easily have extended an SWT application using exactly the same
approach.)
The application's source files are
CanvasTest.java,
MyCanvas.java,
MyCanvasItem.java,
MyCanvasGroup.java,
MyCanvasShape.java,
MyRectCanvasItem.java,
MyCircleCanvasItem.java,
and together they comprise
an AWT application that provides a simple canvas with multiple items.
We want test scripts that test the canvastest
application to be able to query the application's MyCanvas
objects—to retrieve a MyCanvas, to get a
MyCanvas's parent object, to get the canvas's bounding
rectangle, and to get the MyCanvasItem item at a particular
point, or all of the canvas's MyCanvasItem items. In
addition, we want to be able to query MyCanvasItem objects,
to get their bounding rectangles, and so on. To do all this we must
create suitable Inspectable Java classes that Squish can query to get
interfaces through which it can query the application's canvas and
canvas items as if they were standard AWT/SWT objects.
We have put the Inspectable classes in the
MyCanvasFactory.java file in the same directory as
the application's other Java files.
(At present we have no documentation for
MyCanvasFactory.java.
[Under Construction
.]
)
Once the Inspectable classes have been created, Squish must be informed that they exist so that it can make use of them. All that is required to do this is to tell Squish which application the wrapper should be used for and where the wrapper is located. This is done by setting a configuration on the squishserver:
squishserver --config setConfig CanvasTest.jar \ $SQUISHDIR/examples/canvastest/Extension.ini
Here we have used a Unix-style path and assumed that the environment
variable SQUISHDIR has Squish's installation directory.
It doesn't matter what the path used actually is (so long as it is an
absolute path, and the correct one for the
Extension.ini file).
The Extension.ini file must list the AUT's exposed
classes (i.e., those classes that the Inspectable classes handle on
Squish's behalf), and the directory where the extension is located.
Here's the canvastest's
Extension.ini file's contents:
[general] AutClasses="MyCanvasGroup", "MyRectCanvasItem", \ "MyCircleCanvasItem", "MyCanvas" JavaExtensionDir="."
To demonstrate testing the AUT with the wrapper we have provided a
very basic test suite in
squish/examples/java/suite_canvastest_js.
The manifest file must contain an Extension entry that has
as its value the class which has the public static void
init(InspectableRegistry registry) method. This function is the
entry point for the extension and should register the factory class in
the registry.
For applications that load their classes with one or more class loaders
that differ from the system class loader, an entry
LoadAtClass must be added. All RCP fall
in this category.
The value of this entry is the class that will trigger the extension registration, as soon as that class gets loaded by a class loader. This may require some trial and error, because all the fields of the factory classes that get registered must already be known to the class loader.