![]() | Qt-specific |
|---|---|
The Qt Convenience API is only available for the Squish for Qt editions. |
![]() | Native Dialogs on KDE |
|---|---|
To ensure the most reliable recording and replaying of tests, Squish
uses Qt's own dialogs (e.g., for choosing colors, files, and fonts),
rather than the underlying platform's native dialogs. Unfortunately, on
KDE, Qt uses the KDE dialogs and this can cause problems when developing
cross-platform test scripts. The solution is to set the
|
Here are some quick links to the Qt Convenience API's functions:
This function activates the menu item with the specified
itemText in the
objectOrName popup menu, context menu, or menu
bar. (Note that &'s should not be included in the
item text, so if the menu item's text is “Add” (meaning that the text inside
the program is really “&Add”), we just write plain
“Add”.)
This function casts the object of type
QMenuBar, QPopupMenu, or one of their subclasses, to an object of type
QMenuData. The reason the function is needed at all is that test scripts
for Qt 2 and Qt 3 AUTs often need to access a QPopupMenu
or QMenuBar's QMenuData, but due to squishidl's limitation of single
inheritance this is not possible. Nor can Squish's cast function be used in this case because it
only supports casting up or down in the inheritance chain. Qt 4
uses a different menu inheritance structure that only uses
single-inheritance, so Qt 4 menus can be handled directly.
![]() | Qt 2 and Qt 3-specific |
|---|---|
The |
This function casts the object to a QObject. The
object must be a subclass of QObject and
QGraphicsItem—or a class derived from QGraphicsItem—and
where QObject is inherited first. It is not necessary to use this
function for QGraphicsObjects and QGraphicsWidgets since Squish
already knows that these are both QObjects and QGraphicsItems at the
same time.
![]() | Non-QGraphicsItem Objects |
|---|---|
If this function is called on an object that is not derived from QObject and QGraphicsItem—or a class derived from QGraphicsItem—with QObject inherited first, Squish will crash! |
![]() | Qt 4-specific |
|---|---|
The |
Unfortunately QGraphicsItem does not provide support for introspection.
This means that although Squish provides full access to all the
built-in QGraphicsItem classes and their properties and
methods—including their QObject properties and methods if they
inherit QObject and the castToQObject function is
used—none of the properties or methods you add to your own
QGraphicsItem subclasses can be accessed by Squish.
For examples of testing Qt's graphics/view classes see How to Test Graphics Views, Graphics Scenes and Graphics Items (Qt 4) (Section 13.2.6.6).
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) using the specified
button and with the
modifierState modifier state.
It is safe to pass 0 for the coordinates and for the state; and normally
we would pass Qt.LeftButton for the button.
Squish supports this function for view widgets of type QAbstractItemView, and its subclasses, including QListView, QTableView, and QTreeView, and also older Qt 3 classes such as Q3IconView, Q3ListBox, Q3Table, and also classes derived from these types.
See Qt 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. (Note that &'s
should not be included in the tabText, so if the
tab's text is, say, “Advanced”—meaning that the text
inside the program is really “&Advanced”—we just
write plain “Advanced”.)
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 the
modifierState modifier.
See Qt 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 click is made at
position x and y (in the
itemText item's coordinates) using the specified
button and with the
modifierState modifier state.
Squish supports this function for view widgets of type QAbstractItemView, and its subclasses, including QListView, QTableView, and QTreeView, and also older Qt 3 classes such as Q3IconView, Q3ListBox, Q3Table, and also classes derived from these types.
See Qt 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 action is an integer (enum)—for
Qt 4 it can be Qt::CopyAction or
Qt::LinkAction, and for Qt 3 it can be
QDropEvent::Copy or QDropEvent::Link.
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.
This function performs a “flick” operation (a
move or scroll on a QML Flickable). It initiates a flick
of the specified objectOrName item—which
must be a QML Flickable—starting
with the mouse at position x and
y (in the objectOrName
item's coordinates) and moving the mouse by dx
pixels horizontally and by dy pixels vertically.
At the same time the position of the objectOrName
item's contents is moved relative to its previous position by
cdx pixels horizontally and by
cdy pixels vertically.
This function takes a screenshot of the
object window (or widget) and returns the
image as a QPixmap.
The screenshot can easily be saved to file, for example:
widget = waitForObject(objectName)
pixmap = grabWidget(widget)
pixmap.save("screenshot.png")
var widget = waitForObject(objectName);
var pixmap = grabWidget(widget);
pixmap.save("screenshot.png");
my $widget = waitForObject($objectName);
my $pixmap = grabWidget($widget);
$pixmap->save("screenshot.png");
set widget [waitForObject $objectName] set pixmap [invoke grabWidget $widget] invoke $pixmap save "screenshot.png"
For a more generic example that shows how to save a screenshot and how
to compare screenshots, see the files
scriptmodules/python/pixmapcompare.py and
scriptmodules/javascript/pixmapcompare.js.
See the waitForObject and findObject functions for how to get an object
reference to a window or widget.
This function installs an event handler that is applied to all objects
of the className class or to the specified
object or globally (if no
className or object is
specified). 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 on an object of the
className class, or to the specified
object, or globally.
The eventName can be the name any standard Qt
event type such as QKeyEvent event or
QMouseEvent, or one of the Squish convenience event
types listed below:
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 installs a Qt (not Unix!) signal handler that eavesdrops
on the object identified by the given symbolic or real
name. The signalSignature
must be the exact signature used in C++ with no parameter
names—for example, "activated(int)" or
"triggered(QAction*)". The
handlerFunctionName (which must be passed as a
string, not as a function reference), will be called whenever the
specified widget emits the specified signal and will be passed a
reference to the object that emitted the signal, followed by all the
signal's arguments (if there are any).
This function is very flexible in that the object identified by the
name does not have to exist
at the time the function is called, since the object will be looked for
whenever the signal is emitted. The price to be paid for this
flexibility is that the use of this function can significantly slow down
playback if the signal is emitted a lot. If possible it is better to use
the less flexible installSignalHandler
function instead.
Where possible the signal's arguments are passed as types that can be
handled normally such as numbers, strings, or their actual Qt types such
as QAction or QTableWidgetItem. However, some
types are sent as plain Squish Objects; custom types
and other unrecognized types are passed as strings.
This function installs a Qt (not Unix!) signal handler that eavesdrops
on the specified objectOrName widget.
The signalSignature must be the exact signature
used in C++ with no parameter names—for example,
"activated(int)" or "triggered(QAction*)". The
handlerFunctionName (which must be passed as a
string, not as a function reference), will be called whenever the
specified widget emits the specified signal and will be passed a
reference to the object that emitted the signal, followed by all the
signal's arguments (if there are any).
As is usual with Squish functions, the
objectOrName widget must
exist at the time this function is called. This requirement is relaxed
by the installLazySignalHandler function
which can only accept a symbolic or real name, but of an object that
need not exist when the function is called. Nonetheless, it is best to
use this installSignalHandler function whenever possible
since it is potentially a lot faster than the installLazySignalHandler function.
Where possible the signal's arguments are passed as types that can be
handled normally such as numbers, strings, or their actual Qt types such
as QAction or QTableWidgetItem. However, some
types are sent as plain Squish Objects; custom types
and other unrecognized types are passed as strings.
For an example, see How to Use Qt Signal Handlers (Section 13.2.5).
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.
Note that if this function is used to click Q3ListView
objects, Q3TableItem objects, or web objects inside
QtWebKit objects, the modifierState
and button parameters are optional.
See Qt 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 Qt Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function simulates a native mouse click on the specified
objectOrName widget at position
x and y (in the
objectOrName widget's coordinates), using the
specified button and with the
modifierState modifier state.
See Qt Convenience Function Parameters for which
values are valid for the modifierState and for
the button arguments.
This function simulates the user opening a context menu by clicking the
specified objectOrName widget at position
x and y (in the
objectOrName widget's coordinates), and with the
modifierState modifier state.
See Qt Convenience Function Parameters for which
values are valid for the modifierState argument.
This function simulates the user opening a context menu by clicking the
menu option with the specified itemText inside the
objectOrName view widget at position
x and y (in the
itemText item's coordinates), and with the
modifierState modifier state.
Squish supports this function for view widgets of type QAbstractItemView, and its subclasses, including QListView, QTableView, and QTreeView, and also older Qt 3 classes such as Q3IconView, Q3ListBox, Q3Table, and also classes derived from these types.
See Qt Convenience Function Parameters for which
values are valid for the modifierState argument.
This function performs a press and hold operation on the specified
objectOrName item—which
must be a QML object—starting with the mouse
at position x and y (in
the objectOrName item's coordinates) and
optionally moving the mouse by dx pixels
horizontally and by dy pixels vertically if these
offsets are specified. (Note that dx and
dy are relative to the starting mouse position in
QML scene coordinates, not in objectOrName item
coordinates which is normally the case.)
The press and hold operation performed by this function is similar to
what the dragItemBy function does, except
for the “hold” (the initial pause when the mouse is first
pressed down). QML scenes support press and hold by using an invisible
MouseArea item that is overlaid on top of one or more of
the scene's QML items. Squish doesn't record actions for invisible
items so for a press and hold it records the item at the mouse (or
finger for touch screens) position that is actually under the
MouseArea.
This function scrolls the objectOrName widget to
the given position. The
position is an absolute value (i.e., a pixel
offset).
This function sends an event of type eventName to
the objectOrName widget. All the other arguments
(...) are passed on to the the event
constructor—they are typically coordinates, button states, and
similar. The eventName is any of the Qt events
supported by Squish—this includes all the most commonly used
ones, such as,
"QCloseEvent",
"QHideEvent",
"QKeyEvent",
"QMouseEvent",
"QMoveEvent",
"QShowEvent",
"QTabletEvent",
and
"QWheelEvent".
This function can be used in init files to disable
or enable the recording of MouseMove events for certain
widget classes. The class to disable or enable mouse tracking for is
specified by the className parameter. Pass an
onOrOff parameter value of true to
enable mouse tracking or of false to disable mouse
tracking. (By default mouse tracking is off.)
![]() | Wrapper-Specific Initialization |
|---|---|
The
We can have as many |
Example:
setMouseTracking ScribbleArea true
This sets mouse tracking on for an AUT's custom
ScribbleArea class.
To make this work we must tell Squish to execute a file that contains this Tcl script at startup when it is used to test a Qt-based AUT:
squishrunner --config addInitScript Qt /home/harri/qt_init1.tcl
Note that an absolute path must be used.
This function can be used in init files to disable
or enable the recording of mouseDrag statements for certain
widget classes. The class to disable mouse dragging for is specified by
the className parameter. Pass an
onOrOff parameter value of true to
enable mouse drag recording or of false to disable mouse
drag recording. (By default mouse drag recording is on.)
![]() | Wrapper-Specific Initialization |
|---|---|
The
We can have as many |
The init files are Tcl scripts that are registered
with the server and then read before starting any tests. The
registration process is explained in Configuring squishrunner (Section 15.4.1.7) squishrunner.
Example:
setRecordMouseDrag ScribbleArea false
This switches off mouse drag recording for an AUT's custom
ScribbleArea class.
To make this work we must tell Squish to execute a file that contains this Tcl script at startup when it is used to test a Qt-based AUT:
squishrunner --config addInitScript Qt /home/harri/qt_init2.tcl
Note that an absolute path must be used.
This function sets the state of the given
objectOrName window to that specified by the
windowState enumeration. Valid window state
values are:
WindowState.Fullscreen,
WindowState.Maximize,
WindowState.Minimize, and
WindowState.Normal.
The form shown here works for Python and JavaScript. For Perl replace
the period with two colons, e.g., WindowState::Maximize,
and for Tcl use the enum function, e.g., enum
WindowState Maximize. Note that using this function only makes
sense for top-level windows.
This function clicks the “up” button on the
objectOrName spinbox. The function works for
QAbstractSpinBox
and its subclasses, such as QSpinBox and QDoubleSpinBox.
This function clicks the “down” button on the
objectOrName spinbox. The function works for
QAbstractSpinBox
and its subclasses, such as QSpinBox and QDoubleSpinBox.
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.)
![]() | Qt 3-specific |
|---|---|
If the key combination is surrounded by an additional pair of angle
brackets, an accelerator event is sent instead of a key event—for
example, |
Squish provides additional support for the QWebView
class in the form of three additional methods.
This function evaluates the JavaScript code
string in the QWebView's context (i.e., in the context of
the active QWebView page). The result of the last statement
in the code is returned. (See also How to Use evalJS (Section 13.3.5).)
This function returns true if the page has been completely
loaded; otherwise it returns false. A complete and successful
load implies that all of the page's objects can
potentially be accessed. This function can be used
with the waitFor function to wait for a
page to be loaded before accessing it from a test script.
Since page loading, HTTP requests, and so on, are asynchronous, even
after a call to the isPageLoaded function returns
true it is essential that the waitForObject function (or another wait function)
is used to ensure that the specific object or objects of interest are
ready to be accessed. Also, it may be necessary to pass a longer timeout
to the waitForObject function than the
default 20 000 milliseconds. (See also How to Synchronize Web Page Loading for Testing (Section 13.3.7).)
This function changes the QWebView's current page to the
new url.
Qt applications can dynamically load QML code, including custom QML objects, so it is quite possible that AUTs that use QML will have QML objects that are unknown to Squish. This isn't a problem since Squish can still record and playback interactions with such objects, but will do so in terms of the primitives they are built from (e.g., in terms of Rectanges and Texts), rather than with the actual (logical) item types (e.g., CustomButton).
The QML Extension API introduced with Squish 4.1 makes it
possible to make Squish aware of custom QML object types so that
recording and playback can work at a high level (i.e., in terms of the
custom objects themselves rather than with the primitives that they are
built from). Squish comes with a small example that makes use of some
of the QML Extension APIs and that shows how to implement custom
versions of SquishHook functions:
SQUISHDIR/lib/extensions/qt/qml/QtComponentsDesktop.qml.
QML Extensions are standard QML scripts in .qml
files (using the UTF-8 encoding), and using some additional
functionality provided by Squish. Here is the structure of a QML
extension:
import Qt 4.7
import com.froglogic.squish.qml 0.1
SquishHook {
// ... extension code...
}
Squish automatically looks in the
SQUISHDIR/lib/extensions/qt/qml directory for QML
extension files, so all that is needed to “install” a new
QML extension is to move or copy it into this directory.
It is also possible add an additional directory for Squish to search
for QML extensions: simply set the
SQUISH_QML_EXTENSION_PATH environment variable (which you
may need to create) to the directory where you want to keep your QML
extensions (for example, if you don't have write access to
SQUISHDIR/lib/extensions/qt/qml).
Squish's QML Extension API consists of a single item of type
SquishHook. This item provides various properties and
functions which are listed below. A custom QML extension can make use of
these properties and functions—and in some cases override them.
In addition, Squish provides some helper functions to make writing QML
extensions easier.
The API uses the QML types and elements specified in the Qt Reference Documentation: doc.qt.nokia.com/qdeclarativebasictypes.html and doc.qt.nokia.com/qdeclarativeelements.html.
This function returns whether the given item of
type Item is a custom type. (Every QML item that introduces
new properties is considered to be a custom QML type by Qt—and by
this function.)
This function returns whether the given item of
type Item inherits the class specified by the
className string.
This function returns the given item of type
Item's class name if it is a declarative type; otherwise
it returns an empty string.
This function returns the given item of type
Item's URL if the item was loaded from a local file or
remotely; otherwise it returns the item's containing
component's URL (which might be an empty string).
This function returns the container the given
item of type Item is in (itself of
type Item, e.g., a ListView or a
GridView) which is normally also the
item's parent; otherwise it returns
null if the item isn't in a
container.
You can implement your own version of this function in your QML
extension, in which case for any given item you
must return one of the following three values: An
Item (possibly of your own custom type) which contains the
given item. Or null, if you
don't want the given item to have a container (in
which case the view will be considered to be the
item's container). Or, the special value,
unhandled, if you don't want to handle the given
item (e.g., because it is a standard
Item type that you want Squish to handle), since
unhandled tells Squish to handle the
item itself.
This function returns a list of the property names
for the given item of type Item that
should be taken into account when generating a Squish object name for
the item. (This function can be used to achieve
the same kind of control over Squish's naming as editing the Qt
wrapper descriptor file—for which see, Object Name Generation (Section 15.10)—but with finer control possible since
property names can be considered on a per-item basis, not just on a
per-type basis.)
You can implement your own version of this function in your QML
extension, in which case for any given item you
must return either: A list
of property names (as an array of strings) whose values should be used
to create the Squish object name for the given
item. Or, the special value,
unhandled, if you don't want to handle the given
item (e.g., because it is a standard
Item type that you want Squish to handle), since
unhandled tells Squish to handle the
item itself.
This function returns true if the given
item of type Item should be taken
notice of by Squish—for example, visible and available for
picking in the Spy and recorded.
You can implement your own version of this function in your QML
extension, in which case for any given item you
must return one of the following three values: The
value true if you want Squish to take notice of the
given item, or false if you want
Squish to ignore the item, or the special
value, unhandled, if you don't want to handle the given
item (e.g., because it is a standard
Item type that you want Squish to handle), since
unhandled tells Squish to handle the
item itself.
This function returns true if the given
item of type Item is ready to be
interacted with, that is, is visible, enabled, and is in a stable state
(e.g., it is not being or about to be animated).
You can implement your own version of this function in your QML
extension, in which case for any given item you
must return one of the following three values: The
value true if the given item is
ready for interaction, or false the
item isn't ready, or the special value,
unhandled, if you don't want to handle the given
item (e.g., because it is a standard
Item type that you want Squish to handle), since
unhandled tells Squish to handle the
item itself.
This property holds a priority value for the QML extension and has a default value of 0. Squish accessess QML extensions in priority order from highest to lowest.
You can implement your own version of this property in your QML extension to give your extension a priority value higher than 0, e.g., to increase its priority.
This function returns a property value (as a string) for the given
item of type Item's
property (specified as a string).
You can implement your own version of this function in your QML
extension, in which case for any given item and
property you must return
either: A string property value, or the special value,
unhandled, if you don't want to handle the given
item (e.g., because it is a standard
Item type that you want Squish to handle), since
unhandled tells Squish to handle the
item itself.
Note that this function is not called when the
object.property("propertyName")
function is used inside a test script.