Window API in QTP

本文介绍如何利用Windows API来增强QTP(Quick Test Professional)对Internet Explorer弹窗对话框的操作稳定性及效率。通过直接调用API,可以解决QTP内置功能在面对动态属性对话框时的局限性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In my previous post, I talk about How to use windows API send click message to an “ok” button of IE alert dialog. The code used c#. I’d like to transmit them to QTP. It’ll more stable and efficient than QTP built-in Function.

In QTP, if we want to do some action on a dialog, we should add a dialog object to repository.QTP can use their properties to find the dialog then execute command. But the problem is that some dialog’s properties are dynamic. Such as the title of Download Dialog.It lead to QTP couldn’t find exactly object. That’s why our automation script sometimes is slow and broken.

To avoid these tricky, QTP provide us external object. It can be used to call external function. Windows API is good experience. We can use Windows API in QTP. It’s terrific, right? We can using API do everything efficiently.

Following is the script segment to click “OK” button of IE pop dialog.

extern.Declare micHwnd,"FindWindowEx", "user32.dll","FindWindowEx",micHwnd,micHwnd,micString,micString

extern.Declare micLong, "PostMessage", "user32.dll", "PostMessageA", micHwnd, micLong, micLong, micLong

extern.Declare micHwnd,"SetActiveWindow","user32.dll","SetActiveWindow",micHwnd

extern.Declare micInteger,"SetForegroundWindow","user32.dll","SetForegroundWindow",micHwnd

hwndP = extern.FindWindowEx (0,0,"#32770", null)

hwndButton = extern.FindWindowEx (hwndP,0,"Button","OK")

extern.SetForegroundWindow hwndP

extern.SetActiveWindow hwndP

extern.PostMessage hwndButton,&H0F5,0,0

 

Enjoy QTP; enjoy your auto-life!

转载于:https://www.cnblogs.com/gyhanonline/archive/2010/05/01/1725621.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值