【问题标题】:Handle QMessageBox in python unittest with QTest使用 QTest 在 python unittest 中处理 QMessageBox
【发布时间】:2022-01-11 08:13:17
【问题描述】:

我在 python 中自动化 UI 测试。我正在使用 pyqt 和 qtest。如何处理 QMessageBox 并在 unittest 中将其关闭。

【问题讨论】:

    标签: python pyqt5 python-unittest qmessagebox


    【解决方案1】:

    启动计时器,它将在应用程序中寻找活动的模式小部件并关闭它。

    def test_test(self):
    [...]
        # app = QApplication object
        # ui = QWidget object
        qTimer = QTimer(ui)
        qTimer.timeout.connect(handleQMessageBox)
        qTimer.start(100)
        QTest.mouseClick(oneGrButton, QtCore.Qt.LeftButton) # -> this will call QMessageBox
    
    def handleQMessageBox():
        widget = app.activeModalWidget()
        print(widget.text())
        widget.close()
    

    【讨论】:

      猜你喜欢
      • 2016-11-30
      • 1970-01-01
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多