preload

TestComplete – Using ‘File Open’ Dialog

Posted by Albert Gareev on Apr 10, 2012 | Categories: How toRoutinesSource codeTestComplete

Parent page: Using GUI Forms in TestComplete

Even though automation scripts are intended to drive the application under test there are cases when communication with tester is required. With TestComplete, we have a vast arsenal of predefined GUI controls for that (and those, acquainted with Delphi, will be pleasantly surprised by the way it’s organized).

The second post in the series provides an example of using ‘File Open’ dialog.

We begin with a sample form.

Add ‘TOpenDialog’ Icon

Set Dialog Properties

The property names are straight-forward, so I cover only main ones.

  • Name – object name to use in the code;
  • InitialDir – folder to begin browsing from;
  • Filter – to specify what filetypes to display;
  • FileName – will contain the full pathname of the file upon successful selection;
  • Options\ofPathMustExist – set True if selection accepts only existing files;
  • Options\ofFileMustExist – set True if selection accepts only existing files;

These properties can be set in the Property Editor or directly in the code at run-time as in the example below.

Example

'Get object's instance
Set objDlg = UserForms.PlanOpenDlg
'Assign path
objDlg.OpenDialog.InitialDir = "C:\FakePath\Test Plans"
'Set filter
objDlg.OpenDialog.Filter = "XML Test Plans (*.xml)|*.XML"
'Execute as modal and get the status
If objDlg.OpenDialog.Execute Then
  'retrieve the selected file
  sTestPlan = objDlg.OpenDialog.FileName
Else
  'Respond
  MsgBox "Execution cancelled", vbOKOnly
  'exit function or finalize execution
End If

Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported
This work by Albert Gareev is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported.