title: How do you simulate completing a QFileDialog using PyQt and QTest?
body: <p>I want to automate the testing of a GUI. In particular I want to test the &quot;save&quot; option from the file menu. I.e. when the save button is clicked the data from the fields in the UI are collected and then written to a json file.</p>
  <p>The problem is, when the QFileDialog pops up asking for the user to enter the name of the file to save to, I cant get a handle on the dialog to continue testing. How do you automate this bit? I am not sure how to get a handle on the QFileDialog.</p>
  <pre class="lang-py prettyprint-override"><code>    def hdl_save_report_as(self):
          try:
              self.dialog.setDefaultSuffix('json')
              save_file, _ = self.dialog.getSaveFileName(caption=&quot;Save Report&quot;, filter=&quot;JSON Files (*.json)&quot;)
              if save_file:
                  score = self.parent.main_tab_view.get_fields()
                  self.ui_model.report_path = save_file
                  with open(save_file, 'w') as f:
                      json.dump(score, f, indent=4)
          except Exception as e:
              result = dlg.message_dialog(&quot;Exception&quot;, &quot;We ran into an error!&quot;, QMessageBox.Warning, e)
              print(e)
  </code></pre>
  <pre class="lang-py prettyprint-override"><code>    def test_save_report(self):
          self.main_window.menu.bt_save_file.trigger()
          self.main_window.menu.dialog.selectFile('a_test_report.json')
  
          ## save_dialog = QApplication.activeModalWidget()
          # save_dialog = QApplication.activeWindow()
          # children = save_dialog.findChildren()
          # active_line_edit = None
          # confirm_button = None
          # for c in children:
          #     if type(c) is QLineEdit:
          #         if c.hasFocus():
          #             active_line_edit = QLineEdit(c)
          #     # if type(c) is QPushButton:
          #     #     if
          # active_line_edit.setText(&quot;a_test_report&quot;)
          self.assertTrue(os.path.exists(os.path.join(os.getcwd(), 'a_test_report.json')))
  </code></pre>
  <p>I have tried a few different approaches, is there a standard way to do this? Hopefully I have missed something obvious.</p>