我对 Squish 比较陌生,我正在测试使用 Qt5.9 制作的 GUI。
目前我想用一个固定值(大小 12)检查我们应用程序中使用的所有字体的大小。
我已经记录了测试文件并尝试从菜单中转到每个页面并选择匹配“类型:QLabel”和“属性:pointSize”的对象。但这是一个非常缓慢的过程,我需要在每页中选择 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 行,如果我浏览菜单中的每一页并选择所有属于我所需类别的对象,这将花费我很长时间。
更新:
好的,所以我只能通过它们的“类型”搜索对象,并且可以使用以下代码将它们的字体大小与默认值进行比较:
o = findObject("{name~='' type='QLabel'}")
test.compare(str(o.font.pointSize), "12")
现在我的问题是,
如何检查应用程序所有菜单的所有页面,而无需转到每个页面并手动运行此代码?像树遍历这样的东西?例如,这将自动转到菜单的每一棵树并搜索对象,如果它在那里,它会比较字体大小?