我正在使用 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