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 applications it can be done by analyzing the
minimumSizeHint property of Qt widgets. This property holds the recommended minimum size for the widget.
true if the current size of the given widget 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 widgets were analyzed and the outcome of the analysis.
Next we’ll create a function which generates a list of all widgets contained in the given frame or window. Function
fetchAllWidgets(obj) recursively traverses all widgets 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 widget object reference (frame,window) and image filename, where the screenshot of the main widget is stored in the event the case validation for correct layout is not a positive value. All widgets whose size are not sufficient will have a yellow background on the captured screenshot. This is done using the
setStyleSheet("background-color:yellow;") method. An alternative solution is to draw a border for the given widget using
setStyleSheet("border:2px solid rgb(255, 0 , 0);")
To present this solution in action we use Qt application AddressBook. First, we need to make some widget smaller than they should be. To do that we implement function
messWithSizes(), which sets incorrect size for some widgets.
Additionally, the screenshot was generated with failed widgets marked as follows: