Introduction
This Article will help to invoke or call QTP i.e, Quick Test Professional from .Net 2005.
Background
To work with this Tool you need to have basic idea about QTP automation on WebPages and C#.Net windows application.
Using the code
Before getting into coding one must have QTP software install in the system.
Add a Textbox and a button into the design of the form.
As getting into code behind, first add QuickTest.dll as reference to the solution.
Create an instance to the QTP application
QuickTest.Application QTPInstance=new QuickTest.Application();
With this object creation to the applcation we have the access to the methods and properties of the QTP.
QTPInstance.Launch();
QTPInstance.Visible = false;
QTPInstance.Open(txtFolderPath.Text, true, false);
QTPInstance.Test.Run(null, false, null);
Compile the above code into a function named LanuchQTP() so that is can be used many times.
Points of Interest
The main purpose of QTPInvoker is that it can be used for scheduling the automation run (Automation Tester know it.) Now how to do it?
Very simple...use a timer control to invoke QTP at the specified time
void
Schedule_Tick
(object
sender, EventArgs
e)
{
string
datetime=dtPicker.Value.ToString
("MM/dd/yyyy hh:mm:ss tt");
if
(System.DateTime.Now.ToString
("MM/dd/yyyy hh:mm:ss tt") == datetime)
{
Scheduler.Enabled
= true
; // Scheduler is the timer control
cmdRun.Enabled
= true
;
LanuchQTP(); // Invokes QTP
MessageBox
.Show
("QTP Running!", "Message", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
Now how to stop after being invoked? I have used System Diagnostics to kill the application itself
private static void
KillProcess()
{
System.Diagnostics.Process
[] ps = System.Diagnostics.Process.GetProcessesByName
("QTPro")
{
ps.Kill
();
}
System.Diagnostics.Process
[] qs = System.Diagnostics.Process.GetProcessesByName
("QTAutomationAgent")
{
qs.Kill
();
}
}
Any Queries mail to roobansolomonraja@rediffmail.com
Rooban Solomon Raja.D