【发布时间】:2022-01-11 08:13:17
【问题描述】:
我在 python 中自动化 UI 测试。我正在使用 pyqt 和 qtest。如何处理 QMessageBox 并在 unittest 中将其关闭。
【问题讨论】:
标签: python pyqt5 python-unittest qmessagebox
我在 python 中自动化 UI 测试。我正在使用 pyqt 和 qtest。如何处理 QMessageBox 并在 unittest 中将其关闭。
【问题讨论】:
标签: python pyqt5 python-unittest qmessagebox
启动计时器,它将在应用程序中寻找活动的模式小部件并关闭它。
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()
【讨论】: