Application layout validation is a very difficult task no matter the test automation tool. Some level of layout validation can be achieved even using tools which verify object properties and don't rely on screenshot comparison. For Qt Quick applications it can be done by analyzing the
implicitHeight properties of Qt Quick Text items. These properties hold the natural size of the item if no width or height is specified.
true if the current size of the given item isn't less than the values in the
Next, we'll define a wrapper for above function, which calls the Squish API functions
test.fail depending on the
isSufficientlySized result. This allows us to check the Squish Results for which items were analyzed and the outcome of the analysis.
Next we'll create a function which generates a list of all items contained in the given frame or window. Function
fetchAllItems(obj) recursively traverses all visible items with a
text property whose
obj is an ancestor.
Finally, we'll implement the
verifyDialogLayout(dlg, output) function, which is called directly from the test case. It takes two arguments: main item object reference (frame,window) and image filename, where the screenshot of the main item is stored in the event the case validation for correct layout is not a positive value. All text items whose size are not sufficient will be drawn in red on the captured screenshot. This is done setting the
To present this solution in action we use the Qt Quick application AddressBook. First, we need to make some items smaller than they should be. To do that we implement function
messWithSizes(), which sets incorrect size for some items.
Additionally, the screenshot was generated with failed widgets marked as follows: