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)
Code language: CSS (css)

These coordinates are relative to the upper left corner of the item. Let’s look now how to record without them.

Customizing Recording Qt Tests without Coordinates

Many 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"<strong>, "Button"</strong>
Code language: JavaScript (javascript)

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

mouseClick(waitForObject(names.o9_Button)) mouseClick(waitForObject(names.o8_Button)) mouseClick(waitForObject(names.o_Button_2)) mouseClick(waitForObject(names.c_Button))
Code language: CSS (css)

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. 

Leave a Reply

Your email address will not be published. Required fields are marked *

Copy link
Powered by Social Snap