【发布时间】:2019-03-25 11:16:08
【问题描述】:
我正在使用 pytest-qt 来自动化 PyQt GUI 的测试。对话框需要作为测试的一部分进行处理(不应模拟对话框)。
例如,必须处理单击按钮后出现的文件对话框。有2个问题
在按钮单击命令之后,程序控制转到事件处理程序,而不是转到我可以尝试将鼠标单击/击键发送到对话框的下一行。
由于 QDialog 没有添加到主窗口小部件中,因此它没有列在主窗口小部件的子窗口中。那么如何获取QDialog的引用呢?
我尝试了多线程但没用,后来我发现 QObjects 不是线程安全的。
def test_filedialog(qtbot, window):
qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)
print("After mouse click")
#This is where I need to get the reference of QDialog and handle it
【问题讨论】:
-
试试:
print(QtGui.QApplication.topLevelWidgets()) -
谢谢,@eyllanesc 我可以尝试获取对话框参考。但我需要解决第一个问题才能尝试。
标签: python pyqt4 ui-automation black-box-testing pytest-qt