QTPInvoker






1.33/5 (5投票s)
这个工具可以简单地从 .Net 2005 调用 QTP。
引言
本文将帮助您从 .Net 2005 调用或启动 QTP,即 Quick Test Professional。
背景
要使用此工具,您需要对 QTP 自动化(在网页上)和 C#.Net Windows 应用程序 有基本的了解。
使用代码
在开始编码之前,必须在系统中安装 QTP 软件。
在表单设计中添加一个文本框和一个按钮。
进入代码后,首先将 QuickTest.dll 作为引用添加到解决方案中。
创建 QTP 应用程序的实例
QuickTest.Application QTPInstance=new QuickTest.Application();
通过此对象创建,我们就可以访问 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
将上述代码编译成一个名为 LanuchQTP() 的函数,以便可以多次使用它。
关注点
QTPInvoker 的主要目的是它可以用于调度自动化运行(自动化测试人员知道这一点)。现在如何实现?
很简单……使用计时器控件在指定时间调用 QTP
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 是计时器控件
cmdRun.Enabled
= true
;
LanuchQTP(); // 调用 QTP
MessageBox
.Show
("QTP 正在运行!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
现在如何停止调用后?我使用了 系统诊断 来终止应用程序本身
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
();
}
}
如有任何疑问,请发送邮件至 roobansolomonraja@rediffmail.com
Rooban Solomon Raja.D