0

我对 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") 

现在我的问题是,

如何检查应用程序所有菜单的所有页面,而无需转到每个页面并手动运行此代码?像树遍历这样的东西?例如,这将自动转到菜单的每一棵树并搜索对象,如果它在那里,它会比较字体大小?

4

1 回答 1

0

通读“用户指南”后,我找到了解决此问题的方法。如果有人仍然感兴趣:

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

此代码将查找 type='QLabel' 的所有对象并打印它们的字体大小和对象名称。

于 2017-08-23T12:48:42.683 回答