Squish - 根据类型和 属性 在基于 QT 的 GUI 的所有菜单中搜索所有对象
Squish - Seaching all the Objects in all the Menus of a QT based GUI based on their Type and Property
我对 Squish 比较陌生,我正在测试我们用 Qt5.9 制作的 GUI。
目前我想用固定值(12 号)检查我们应用程序中使用的所有字体的大小。
我已经记录了测试文件并尝试从菜单转到每一页,select 匹配 "type: QLabel" 和 "property: pointSize" 的对象。但这是一个非常缓慢的过程,我需要在每个页面中 select 喜欢 200 个对象。我已经从菜单中浏览了 3 页,我的代码已经超过 500 行。这是代码的一部分:
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)
这个过程有效,但我的最终代码将超过 20k 行,如果我浏览菜单中的每一页和 select 属于我所需类别的所有对象,我将花费很长时间。
更新:
好的,所以我只能通过他们的 "type" 搜索对象,我可以使用以下代码将他们的字体大小与默认值进行比较:
o = findObject("{name~='' type='QLabel'}")
test.compare(str(o.font.pointSize), "12")
现在我的问题是,
如何检查应用程序所有菜单的所有页面,而无需手动访问每个页面和 运行 此代码?像树遍历之类的东西?例如,这将自动转到菜单的每一棵树并搜索对象,如果它在那里,它会比较字体大小?
通读 "User Guide" 后,我找到了解决此问题的方法。如果还有人感兴趣:
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
此代码将查找类型='QLabel' 的所有对象并打印它们的字体大小和对象名称。
我对 Squish 比较陌生,我正在测试我们用 Qt5.9 制作的 GUI。
目前我想用固定值(12 号)检查我们应用程序中使用的所有字体的大小。
我已经记录了测试文件并尝试从菜单转到每一页,select 匹配 "type: QLabel" 和 "property: pointSize" 的对象。但这是一个非常缓慢的过程,我需要在每个页面中 select 喜欢 200 个对象。我已经从菜单中浏览了 3 页,我的代码已经超过 500 行。这是代码的一部分:
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)
这个过程有效,但我的最终代码将超过 20k 行,如果我浏览菜单中的每一页和 select 属于我所需类别的所有对象,我将花费很长时间。
更新:
好的,所以我只能通过他们的 "type" 搜索对象,我可以使用以下代码将他们的字体大小与默认值进行比较:
o = findObject("{name~='' type='QLabel'}")
test.compare(str(o.font.pointSize), "12")
现在我的问题是,
如何检查应用程序所有菜单的所有页面,而无需手动访问每个页面和 运行 此代码?像树遍历之类的东西?例如,这将自动转到菜单的每一棵树并搜索对象,如果它在那里,它会比较字体大小?
通读 "User Guide" 后,我找到了解决此问题的方法。如果还有人感兴趣:
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
此代码将查找类型='QLabel' 的所有对象并打印它们的字体大小和对象名称。