如何在pytest-qt中处理模态对话框而不模拟对话框

问题描述 投票:0回答:1

我使用pytest-qt自动测试PyQt GUI。对话框需要作为测试的一部分进行处理(不应该模拟对话框)。

例如,必须处理按钮单击后出现的文件对话框。有两个问题

  1. 按钮单击命令后,程序控件转到事件处理程序,而不是下一行,我可以尝试向对话框发送鼠标点击/按键。
  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
python pyqt4 ui-automation black-box-testing pytest-qt
1个回答
0
投票

它可以使用QTimer完成。

def test_filedialog(qtbot, window):
    def handle_dialog():
        # get a reference to the dialog and handle it here
    QTimer.singleShot(500, handle_dialog)
    qtbot.mouseClick(window.browseButton, QtCore.Qt.LeftButton, delay=1)

有关更多详细信息,请参阅此link

© www.soinside.com 2019 - 2024. All rights reserved.