Ways to Launch your application | Quick Test Professional(QTP)
.

Ways to Launch your application

Four different ways to launch your application are mentioned below:

1) SystemUtil.Run

SystemUtil.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) InvokeApplication

This 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 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) Trivial but useful method

If nothing works out you might try this

You can 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:\WINNT\system32\notepad.exe"
Dialog("Run").WinButton("OK").Click

If you want to keep track of further articles on QTP. I recommend you to subscribe via RSS Feed. You can also subscribe by Email and have new QTP articles sent directly to your inbox.

25 comments:

Narender reddy said...

Hi Friends

i need some information from you
i need some sample applications to improve my knowledge on Q.T.P rather than Flight application
that means any web application or Hospital Management application or Banking application
From where i can get the application i think a good response from this blog

Ramesh said...

Hi Good morning.

This is Ramesh from Mphasis. I am working on one application using ASP.Net 2.0 where QTP validation is used. It is not to validate the existing ASP.Net application, but validate other test cases. I have to launch QTP using ASP.Net. Intially QTP was installed in all the clients system but now they want to install in Server. Now every one wants to use the QTP installed in the server.

Is it feasible?

Could you Please Proivde me the QTP license information provided by HP currently ?

Anonymous said...

if u want to acces from server, you must buy concurant licence from HP.

Thanks & Regards.
ramji

sourav said...

Hey ankur I had a question.
When i try to open a .bat file using Wscript.shell , the application opens but it is not visible..what can be the possible way to make the application visible for further operation. When we double click on the bat file the application opens and it is visible.. but through qtp it is not visible.

chetan said...

Hi Ankur,

I am really happy to see this blog, its really helpful for newbies like me.
I have one problem whenever I run IE through following script it launches two IE.
Systemutil.Run "C:\Program Files\Internet Explorer\IEXPLORE.exe"
Please tell me what would be the reason and possible solution.

Thanks,
Chetan

Anonymous said...

hi friends

i have installed QTP 9.2 version on my PC. I am able to create a script but while running the script it pops up an error message "cannot find object...." I am using the application which suppotrs c sharp. So can anyone help me out how can i get rid of this error or how 2 add c sharp addins into my PC?

SiDdHartHa said...

go to hp site and download .net addins.....

may be it works better

Ram said...

Hi,
I like this QTP blog site. How can I post the questions? I'm new to QTP. I just started a .net project. I'm able to open the application automatically and recored some steps. But when I'm running the test, application is opening and rest of the steps are not running at all. is any body can help me?
Regards
Ram.
vramu1@gmail.com

Anonymous said...

To open notepad app use following code.

Window("Program Manager").WinListView("SysListView32").Activate("Run")
Dialog("Run").WinEdit("Open:").Type("Notepad")
Dialog("Run").WinButton("OK").Click
Window("Notepad").Close

Anonymous said...

hi ankur,
Really very exicted after this site abt QTP i was searching from many days .Thanku 4 solving all doubts and hav a excellent site. iam Doing my course still.

my doubt is need detail use of Automation Frame work? wht are the best possible ways to write pgms.


Thanks&Regards,
Priyanaka
my mailId: meen_19@rediffmail.com

Anonymous said...

hi ankur,
Really very exicted to see this site abt QTP i was searching from many days .Thanku 4 solving all doubts and hav an excellent site. iam Doing my course on QTP still.

my doubt is y we go for AFW & detail use of Automation Frame work? wht are the best possible ways to write pgms.


Thanks&Regards,
Priyanaka
my mailId: meen_19@rediffmail.com

Anonymous said...

Can someone please help me how to open a .pub file with notepad? Is there any command in QTP (like openAsTextStream)?

Nygel De said...

Hi,

I just want to ask if there is a script to allow me to know if the application i am testing is already running?

Ankur said...

@nygel de: There is a link on the right hand side "Check already running process".

Others: Please use Testing Tools forum for posting QTP questions.

Ashish said...

I spent two bad days on solving the silly problem i'm facing.
It's a windows application. There's a dialog which has three winbuttons, whose positions keep on changing. when i look at their properties, there is no text or attached text.
I'm unable to identify the button i want to click.
can someone please tell me, how to do that ?? i have enabled smart identification, but that doesn't work either.
Is there a property that i can define, which could help me click on the object i want.
Can't use index or location, as the position keeps on changing on the screen.

Thanks and Advance,
Ashish

meet thakkar said...

what about security in the QTP???

and is it reliable????

vikas said...

Hi i am new in qtp. what is first step done in any project for using qtp. can u provide me some example so that i got cleared with basic fundamentals with practical knowladge. my email id is vikas41@gmail.com

Thanks,
vikas

Anonymous said...

Hi Ankur,

I have attended the QTP training program conducted by HP and started doing a prototype for our application.And realized, the cliche that practical is different from theory holds good here too.I have been facing a couple of issues and on googling, I found the solution for couple of problems on your site. You write detailed blogs which even a person not familiar with QTP would understand. Thanks for sharing your knowledge.

I have a query regarding parameter passing between actions.Could you please explain in detail as to how it works.

Thanks,
Nashi

Anonymous said...

set fso=createobject("scripting.filesystem")

set FD=fso.opentextfile("c:\Textfile.txt",8,flase)

FD.write("Hello World")

Gursharan said...

Some Examples of launching an application:

'launching the application using SystemUtil
SystemUtil.Run "C:\windows\system32\calc.exe"

'Closing the application using SystemUtil
Systemutil.CloseProcessByName "calc.exe"

'Launching application using invoke application option. It is not recommended to use as it is for backward compatability of QTP.
invokeapplication "c:\windows\system32\calc.exe"

'Closing the application using SystemUtil
Systemutil.CloseProcessByName "calc.exe"

'Launching the application using VB Script

Dim oLaAp
Set oLaAp = CreateObject ("Wscript.shell")
oLaAp.Run Chr(34) & "c:\windows\system32\calc.exe" & Chr(34)
Set oLaAp = Nothing

'Closing the application using SystemUtil
Systemutil.CloseProcessByName "calc.exe"

Sreedevi said...

Hi, how can we schedule a test run from Quality Center to run a certain number of tests at the specified time?

Ankur said...

Yeah Sreedevi.

Check the post on QTP with Quality Center

Sreedevi said...

Hi Ankur,
Thanks for your reply. I have one more question.
Is there any way through which we can test UI of the Microsoft outlook using VBScript in QTP?
For ex: to view grouping of certain outlook calendar items according to their priority.

Venkatbatchu said...

Hi,
I have been spending more than 8 hours to get the picture on the below scenario and finally i am posting my query to this forum
Scenario:
I have a one link called "Data Name" under this i could see some 200 data field values . By default all these field values shown in ascending order and when u click on this link manually page refreshes and still it will show the data fields in ascending order(Note: Here number of clicks on this link is "one" as of now) and by click on this link once again then the data field values will be shown in descneding order(Note: Here number of clicks on this link is "two" as of now)

Query: Here i need to find the number of clicks on a link "Data Name"
by this way i can put this logic in my code (Ex: if number of clicks are even then it will display in descending order, if number of clicks on this link are odd number then i could consider that displaying of fields are in ascending order

Please help in this regard to find the number of clicks on a particular link

Anonymous said...

Hello Ankur

Plz help me out..

I have QTP 9.2 Setup but don't know how can i Enable that Air Ticket Booking Application....

or i have to download seperate that Air Ticket Application...



Plz Tell me what i have to do...?


My Mail-Id is : jatinderjain@gmail.com