Using built-in and system dialogs in QTP
Even though automated testing scripts are intended to communicate with application under test there are cases when communication with tester is required. With QTP, we can use either built-in MsgBox / InputBox functions or link standard Windows dialogs through COM.
MsgBox
Use this function to report information (like value of a variable) during debugging or to report a critical issue that caused test execution to stop.
MsgBox(prompt[, buttons][, title][, helpfile, context])
'Example. Dim MyVar MyVar = MsgBox ("Hello World!", 65, "MsgBox Example") ' MyVar contains either 1 or 2, depending on which button is clicked.
For a complete description please refer to Quick Test Professional Help.
InputBox
Use this function to ask a tester to input a short simple value, like environment name. Do not use InputBox dialog for a long text input, like file path, or complex data input, like username/password.
InputBox(prompt[, title][, default][, xpos][, ypos][, helpfile, context])
'Example Dim Input Input = InputBox("Enter your name") MsgBox ("You entered: " & Input)
For a complete description please refer to Quick Test Professional Help.
Custom Dialogs
If you want to create a custom dialog using DotNetFactory – please refer to the following article.
Standard Dialogs – MSComDlg
The MSComDlg component could be used to display several types of dialogs: open file, save file, printer, color and font dialogs.
'Example Dim CDLG Set CDLG = CreateObject("MSComDlg.CommonDialog") With CDLG .DialogTitle = "Get me a File!" .Filter = _ "Documents|*.doc|Templates|*.dot|Text Files|*.txt" .ShowOpen MsgBox .FileName End With Set CDLG = Nothing
You can refer to the following resource for additional information: MSDN Article Enhance Your Apps with Common Dialogs
You may experience a licensing issue with this control if you don’t have Visual Studio installed on the machine executing the code that uses MSComDlg. To resolve the issue please refer to the article or use another dialog component.
Standard Dialogs – UserAccounts
The UserAccounts component is available in Windows family beginning from Windows XP.
'Create Dialog Set objDialog = CreateObject("UserAccounts.CommonDialog") objDialog.Filter = "Test Plan Spreadsheets|*.xls" objDialog.FilterIndex = 1 objDialog.InitialDir = "C:\Test Suite\Test Plans" 'Show Dialog intRC = objDialog.ShowOpen sTestPlan = objDialog.FileName 'release Set objDialog = Nothing
You can refer to the following resource for additional information and step-by-step explanations: How Can I Show Users a Dialog Box for Selecting Files?