Header Ads

Methods to Open an Application in QTP or VB Script

A lot of time we the automation test engineers need to face this situation that we need to open an application through our script. It is a sophisticated approach to open the application during run time.I tried to sum up all the method possible to open an application during run time.

This post talks about a method Four different ways to launch your application are mentioned below:

1) SystemUtil.RunSystemUtil.Run ( FileName, Parameters, Path, Operation )
FileName - The name of the file you want to run.
Parameters - If the specified FileName is an executable file, use the Parameters argument to specify any parameters to be passed to the application.
Path - The default directory of the application or file.
Operation - The action to be performed. If this argument is blank (""), the open operation is performed.

The following operations can be specified for the operation argument of the
SystemUtil.Run method:open - Opens the file specified by the FileName parameter. The file can be an executable file, a document file, or a folder. Non-executable files are open in the associated application.edit - Launches an editor and opens the document for editing. If the FileName argument does not specify an editable document file, the statement fails.explore - Explores the folder specified by the FileName argument.find - Initiates a search starting from the specified folder path.print - Prints the document file specified by the FileName argument. If the specified file is not a printable document file, the statement fails.Example:SystemUtil.Run "D:\My Music\Breathe.mp3","","D:\My Music\Details","open"

2) InvokeApplicationThis command is now mainly used for the backward compatability ie to use with the lower versions(below QTP 6.0) of QTP.InvokeApplication("Full URL as Parameter")Example:InvokeApplication "C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.yahoo.com"
3) VBscript to invoke application1. Create a "WScript.shell" object.

2. Use the "run" object to launch the application. If the path to your executable contains spaces, use Chr(34) to ensure the path is contained within double quotes.3. When done, set the shell object to nothing to release it.Example:
Dim oShellSet oShell = CreateObject ("Wscript.shell")
Example 1 - run a batch file:
oShell.run "notepad"
Start -> Run dialog of Windows.1. Add the Windows Start button to the Object Repository using the "Add Objects" button in Object Repository dialog.
2. Open the Run dialog (Start -> Run), and learn the "Open" edit field and the "OK" button into the Object Repository.
3. Switch to the Expert View, and manually add the lines to open the Run dialog.Example:Window("Window").WinButton("Button").ClickWindow("Window").Type("R")

4. Manually enter the lines to enter the information to launch the application, and click the "OK" button of the Run dialog.
Example:Dialog("Run").WinEdit("Open:").Type "c:\WINNT\system32\notepad.exe"

Powered by Blogger.