I am comparatively new to Squish and I am testing our GUI which is made with Qt5.9.
Currently I want to check the size of all the fonts used in our application with a fixed value (Size 12).
I have recorded the test file and tried to go to every page from the menu and select the objects which matches "type: QLabel" and "property: pointSize". But it is a very slow process and I need to select like 200 Objects in each page. I have gone through 3 pages from the menu and my code is already 500+ lines. Here is a part of the code:
def main():
startApplication("ke3600")
test.compare(waitForObjectExists(":_QLabel").font.bold, False)
test.compare(waitForObjectExists(":_QLabel").font.pointSize, 12)
test.compare(waitForObjectExists(":_MainWindow").font.bold, False)
test.compare(waitForObjectExists(":_MainWindow").font.pointSize, 12)
test.compare(waitForObjectExists(":Widget_QWidget").font.bold, False)
test.compare(waitForObjectExists(":Widget_QWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":m_voltage_LineVoltageWidget").font.bold, False)
test.compare(waitForObjectExists(":m_voltage_LineVoltageWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":m_dslSyncTime_QLabel").font.bold, False)
test.compare(waitForObjectExists(":m_dslSyncTime_QLabel").font.pointSize, 12)
test.compare(waitForObjectExists(":m_clock_QLabel").font.bold, False)
test.compare(waitForObjectExists(":m_clock_QLabel").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget_QStackedWidget").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget_QStackedWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.flashPage_QWidget").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.flashPage_QWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.moduleframe_QFrame").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.moduleframe_QFrame").font.pointSize, 12)
test.compare(waitForObjectExists(":moduleframe.label_QLabel").font.bold, False)
test.compare(waitForObjectExists(":moduleframe.label_QLabel").font.pointSize, 16)
test.compare(waitForObjectExists(":moduleframe.moduleLabel_QLabel").font.bold, False)
test.compare(waitForObjectExists(":moduleframe.moduleLabel_QLabel").font.pointSize, 16)
test.compare(waitForObjectExists(":moduleframe.passLabel_QLabel").font.bold, False)
test.compare(waitForObjectExists(":moduleframe.passLabel_QLabel").font.pointSize, 16)
test.compare(waitForObjectExists(":m_stackedWidget.errorLabel_QLabel").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.errorLabel_QLabel").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.flashProgressBar_QProgressBar").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.flashProgressBar_QProgressBar").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.applPage_QWidget").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.applPage_QWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.menuPage_QWidget").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.menuPage_QWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.m_menuName_QLabel").font.bold, True)
test.compare(waitForObjectExists(":m_stackedWidget.m_menuName_QLabel").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.subTitle_QLabel").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.subTitle_QLabel").font.pointSize, 12)
test.compare(waitForObjectExists(":m_stackedWidget.listView_MenuView").font.bold, False)
test.compare(waitForObjectExists(":m_stackedWidget.listView_MenuView").font.pointSize, 12)
test.compare(waitForObjectExists(":listView.qt_scrollarea_hcontainer_QWidget").font.bold, False)
test.compare(waitForObjectExists(":listView.qt_scrollarea_hcontainer_QWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":listView_QScrollBar").font.bold, False)
test.compare(waitForObjectExists(":listView_QScrollBar").font.italic, False)
test.compare(waitForObjectExists(":listView.qt_scrollarea_vcontainer_QWidget").font.bold, False)
test.compare(waitForObjectExists(":listView.qt_scrollarea_vcontainer_QWidget").font.pointSize, 12)
test.compare(waitForObjectExists(":listView_QScrollBar_2").font.bold, False)
test.compare(waitForObjectExists(":listView_QScrollBar_2").font.pointSize, 12)
test.compare(waitForObjectExists(":listView.Broadband_QModelIndex").font.bold, False)
test.compare(waitForObjectExists(":listView.Broadband_QModelIndex").font.pointSize, 12)
test.compare(waitForObjectExists(":listView.Copper Test_QModelIndex").font.bold, False)
test.compare(waitForObjectExists(":listView.Copper Test_QModelIndex").font.pointSize, 12)
test.compare(waitForObjectExists(":listView.Analysis_QModelIndex").font.bold, False)
test.compare(waitForObjectExists(":listView.Analysis_QModelIndex").font.pointSize, 12)
test.compare(waitForObjectExists(":listView.Setup_QModelIndex").font.bold, False)
test.compare(waitForObjectExists(":listView.Setup_QModelIndex").font.pointSize, 12)
test.compare(waitForObjectExists(":listView.Address Book_QModelIndex").font.bold, False)
test.compare(waitForObjectExists(":listView.Address Book_QModelIndex").font.pointSize, 12)
test.compare(waitForObjectExists(":Battery_Battery").font.bold, False)
test.compare(waitForObjectExists(":Battery_Battery").font.pointSize, 12)
This process works but my final code will be more than 20k lines and will take me ages if I go through every pages from my menu and select all the objects that falls into my required category.
Update:
Ok so I was able to search for an object by their "type" only and I can compare their font size with a default value using the following code:
o = findObject("{name~='' type='QLabel'}")
test.compare(str(o.font.pointSize), "12")
Now my question is,
How do I check all the pages of all the menus of the application without going to each and every page and running this code manually? Something like tree traversal? For example this will automatically go to every tree of the menu and search for the object and if it's there, it will compare the font size?
After reading through the "User Guide", I was able to find a solution of this problem. If anyone is still interested:
def main():
startApplication("ke3600")
objects = find_all_objects("{type='QLabel'}")
# Iterate over all the found objects:
for obj in objects:
test.log(str(obj.font.pointSize))
test.log(str(obj.objectName))
pass
def find_all_objects(obj_real_name):
if "occurrence=" in obj_real_name:
test.warning("Real name must not contain the occurrence property on the actual object (but it is okay for containers): %s" % obj_real_name)
objects = []
try:
one_object = findObject(obj_real_name)
objects.append(one_object)
# Occurrence of second instance for Java, MFC, UIA:
occurrence = 1
# Occurrence of second instance for Qt, Web:
if hasattr(one_object, "metaObject") or hasattr(one_object, "nextSibling"):
occurrence = 2
while True:
backup = testSettings.objectNotFoundDebugging
testSettings.objectNotFoundDebugging = False
try:
obj_real_name_n = "{occurrence='%s' %s}" % (occurrence, obj_real_name[1:-1])
one_object = findObject(obj_real_name_n)
objects.append(one_object)
occurrence += 1
finally:
testSettings.objectNotFoundDebugging = backup
except LookupError:
# No more occurrences found
pass
return objects
This code will look for all the objects of type='QLabel' and print their font size and object name.