Saturday, December 10, 2011

How to Opening and Closing Applications Programmatically in QTP

Opening and Closing Applications Programmatically
In addition to using the Record and Run Settings dialog box to instruct QuickTest to open a new application when a test run begins, or manually opening the application you want to test, you can insert statements into your test that open and close the applications you want to test.

You can run any application from a specified location using a SystemUtil.Run statement. This is especially useful if your test includes more than one application, and you selected the Record and run test on any application check box in the Record and Run Settings dialog box. You can specify an application and pass any supported parameters, or you can specify a file name and the associated application starts with the specified file open.

You can close most applications using the Close method. You can also use SystemUtil statements to close applications.

For example, you could use the following statements to open a file named type.txt in the default text application (Notepad), type happy days, save the file using shortcut keys, and then close the application:

SystemUtil.Run "C:\type.txt", "","",""
Window("Text:=type.txt - Notepad").Type "happy days"
Window("Text:=type.txt - Notepad").Type micAltDwn & "F" & micAltUp
Window("Text:=type.txt - Notepad").Type micLShiftDwn & "S" & micLShiftUp
Window("Text:=type.txt - Notepad").Close


Note:

When you specify an application to open using the Record and Run Settings dialog box, QuickTest does not add a SystemUtil.Run statement to your test.
The InvokeApplication method can open only executable files and is used primarily for backward compatibility.

No comments:

Post a Comment