Article - Layout validation for text truncation in Qt applications

Skip to end of metadata
Go to start of metadata

Introduction

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.

Solution

This article presents a JavaScript solution. Similar solutions can be implemented in other scripting languages supported by Squish. We'll start by implementing a function, which returns true if the current size of the given widget isn't less than the values in the minimumSizeHint property.

Next, we'll define a wrapper for above function, which calls the Squish API functions test.pass or 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);")

Example

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.

Squish IDE: Test Results View

Additionally, the screenshot was generated with failed widgets marked as follows:

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.