Qt QML Type Combobox Item cannot be accessed in Squish

703 Views Asked by At

I am trying to automate my GUI testing with Squish Qt tool. My Qt application was developed using QML scripts. For my automation, I have to select item in a Combobox(QML Type), this is the code i am using for that.

import squish

squish.startAllication("My App")
squish.mouseClick(squish.waitForObjectItem("QQuickView_1.Settings_1", "Mode 2"))

From Squish Manual I found this function to access Combobox item.

waitForObjectItem(objectOrName, itemOrIndex, timeoutMSec);

Waits until the objectOrName object is accessible (i.e., it exists and is visible and enabled), and contains an item that is identified by the itemOrIndex and that is itself accessible.

But While using this function I am getting Object not found error.

And I have found "The waitForObjectItem function can now be used with QComboBox (Qt 3) and Q3ComboBox (Qt 4) controls " this from the manual. Here it says that it will have support for QCombobox only.

How we can access QML Type Combo box?

1

There are 1 best solutions below

0
On

As you found, waitForObjectItem() pre-dates and does not support QML/QtQuick. (Unfortunately the manual does not say that there.)

It looks like you are manually writing your automation script. This is something that I advise to do only after knowing the basics of Squish, for which I recommend to go through the tutorial of Squish for Qt first, at minimum.

Furthermore, if you don't know how to solve something, I recommend to start up the Squish IDE and to record the desired interaction. Afterwards, in an ideal case, you have a recorded script snippet that replays properly. And this script snippet and the object names used in it you can then study to learn how to do what you need in your manually written script code.

As for accessing a QML/QtQuick ComboBox, this is what Squish is recording for me in case of the Qt example "quickcontrols2/gallery":

def main()
    startApplication(os.path.expanduser("~/qt/5.15.2/gcc_64/bin/gallery"))

    # Open menu:
    mouseClick(waitForObject(names.image_IconImage_2), 11, 15, Qt.LeftButton)

    # Select menu entry "ComboBox":
    mouseClick(waitForObject(names.comboBox_ItemDelegate), 48, 25, Qt.LeftButton)

    # Expand ComboBox control:
    mouseClick(waitForObject(names.page_ComboBox), 104, 13, Qt.LeftButton)

    # Click on one of the items:
    mouseClick(waitForObject(names.o_Rectangle), 55, 24, Qt.LeftButton)

    # Expand ComboBox control:
    mouseClick(waitForObject(names.page_ComboBox), 110, 13, Qt.LeftButton)

    # Click on one of the items:
    mouseClick(waitForObject(names.o_Rectangle), 63, 22, Qt.LeftButton)

As you can see, this is not "high level" ("select entry X in this ComboBox"), instead, it records interactions with objects from the object tree.

There is nothing that will stop you from writing convenience functions like selectComboBoxEntry(obj, itemName), but you will have to do this yourself. And for this you need to understand the basics of Squish, the object tree, object names and object identification, and so on. (All of these can be found in the manual.)