Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / .NET

QTPInvoker

1.33/5 (5 votes)
24 Feb 2008CPOL1 min read 1  
This tool simple invokes the QTP from .Net 2005

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(); // To launch the application

     QTPInstance.Visible = false; // To make the applcation visible while running

     QTPInstance.Open(txtFolderPath.Text, true, false);// this will open the script file of automation, extension .mts

     QTPInstance.Test.Run(null, false, null);
// this will run the automation script 

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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)