Recording GUI Test Scripts without Mouse Coordinates


When playing back a recorded GUI test, typically, the exact positioning of the mouse does not matter; rather, we care more whether the mouse clicks inside the desired UI item. Cases where mouse coordinates are required, however, do arise in practice. (Think of a test of a text editor, where you would need to place the cursor at a precise character.) For most types, Squish will, by default, record mouse clicks with (x,y) coordinates and write these to your script. Here, we show you how to configure Squish to record without coordinates for specific QML types. The removal of coordinate information from your script will simplify test scripts, improve test script readability and ease test script maintenance.

A Qt QML Example

Let's look at an example script where we've interacted with a custom (not derived from BasicButton) Button QML Type. By default, our mouse clicks are recorded with (x,y) coordinates:

mouseClick(waitForObject(names.o9_Button), 4, 34, Qt.LeftButton)
mouseClick(waitForObject(names.o8_Button), 27, 31, Qt.LeftButton)
mouseClick(waitForObject(names.o_Button_2), 13, 37, Qt.LeftButton)
mouseClick(waitForObject(names.c_Button), 13, 28, Qt.LeftButton)

These coordinates are relative to the upper left corner of the bounding-box of the Item. They are not screen coordinates. By default, these coordinates are recorded because, the logic goes, it is easier to remove them later, than to add them.

We would be perfectly happy if the clicks were each in the middle of the each Button. Let's look now how to record Button clicks without coordinates.

Customizing Recording Qt Tests without Coordinates

Some interesting settings for customizing the way Qt application tests are recorded in Squish are located in the qtwrapper.ini file, located in SQUISHDIR/etc/.

RecordWithoutCoordinates is one option in qtwrapper.ini, and it is a list of types. These types can be C++ or QML types. BasicButton and QQuickText are both already there, but not our user-defined Button from the example script above. We can simply add it to the list, and our changes will affect all future recordings:

RecordWithoutCoordinates = "BasicButton", "QQuickText", "Button"

Going back to our earlier example, with the added customization for our Button type, our script now looks like the following:


Wrap Up

For Button-like types where you always want to click in the middle of the item, adding those types to the RecordWithoutCoordinates list simplifies your recorded test scripts, while making them more robust, easier to follow and (potentially) debug. 


    The Qt Company acquired froglogic GmbH in order to bring the functionality of their market-leading automated testing suite of tools to our comprehensive quality assurance offering.