There are various ways using which we can launch applications in QTP/UFT. In this article, let us discuss five such different methods:

Launch Applications Using QTP

1. SystemUtil.Run

SystemUtil.Run ( FileName, Parameters, Path, Operation )
  •  FileName – The name of the file you want to run.
  • Parameters (optional) – If the specified FileName is an executable file, use the Parameters argument to specify any parameters to be passed to the application.
  • Path(optional) – The default directory of the application or file.
  • Operation(optional) – 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 Usage: 

SystemUtil.Run "C://Program Files/Internet Explorer/IEXPLORE.EXE"

2. InvokeApplication

This command is now mainly used for the backward compatibility ie to use with the lower versions (below QTP 6.0) of QTP.

InvokeApplication("Full URL as Parameter")

Example Usage:

InvokeApplication "C://Program Files/Internet Explorer/IEXPLORE.EXE http://www.yahoo.com"

3. VBscript to invoke application

  1. 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 "F://jdk1.3.1/demo/jfc/SwingSet2.bat"
'Example 2 - run a Java jar file:
oShell.run "java -jar F://jdk1.3.1/demo/jfc/SwingSet2/SwingSet2.jar"
'Example 3 - launch Internet Explorer:
oShell.Run Chr(34) & "C://Program Files/Internet Explorer/IEXPLORE.EXE" & Chr(34)
Set oShell = Nothing

4. IE Automation Object Model

Set oIE = CreateObject("InternetExplorer.Application")
oIE.Navigate "http://www.google.com/"
oIE.Visible = True
......
......

Set oIE = Nothing

5. Trivial but useful method

If nothing works out you might try this

Use the 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://Windows/System32/notepad.exe"
Dialog("Run").WinButton("OK").Click

6. WebUtil Object

In UFT 14.01 update, HPE introduced two new methods for WebUtil Object. LaunchBrowser and LaunchMobileBrowserWithID

Using LaunchBrowser method you can launch applications across desktop and mobile devices. The syntax for LaunchBrowser is

WebUtil.LaunchBrowser Browser, [device_model, device_manufacturer, device_ostype, device_osversion]

where:

  • Browser: Name of browser to be launched. Ex: CHROME, FIREFOX, IE
  • device_model: The model of the selected device.
  • device_manufacturer: The name of manufacturer of the selected device.
  • device_ostype: The OS running on the device.
  • device_osversion: The OS version running on the selected device.

Parameters in square brackets are optional and they are meant to be used for mobile browsers only.

Example:

The following example launches the Chrome browser on an iOS Apple 5s device.

WebUtil.LaunchBrowser "MOBILE_CHROME", "Apple_5s", "Apple", "IOS", "10.1.3"

Using LaunchMobileBrowserWithID method you can launch a mobile browser on an iOS or an Android device using the Mobile Center’s device ID.

WebUtil.LaunchMobileBrowserWithID Browser, device_ostype, device_id

where

  • Browser: Name of browser to be launched. Ex: MOBILE_HPWEB, MOBILE_CHROME, MOBILE_SAFARI
  • device_ostype: The OS running on the device.
  • device_id: The id assigned to the device by Mobile Center.

Example:

WebUtil.LaunchMobileBrowserWithID "MOBILE_CHROME", "IOS", "02"

If you want to keep track of further articles on UFT (QTP). I recommend you to subscribe by Email and have new UFT articles sent directly to your inbox.

Subscribe to get free updates on UFT!

LearnQTP is the most popular site on UFT (formerly QTP).

Enter your first name and email address below to instantly subscribe and download an eBook on Optimizing UFT Scripts. In future, we will make sure you get new tips & tricks on UFT delivered direct to your email box.

Please check your email and confirm free subscription!