如何在QTP中使用IntelliSense(智能敏感)访问自定义的VBS函数和对象?

如何在 QTP 中使用 IntelliSense (智能敏感)访问自定义的 VBS 函数和对象?

 

由于 QTP 采用 VBS 作为脚本开发语言,具有天生的 OO 缺陷,在 IntelliSense 方面也由于 QTP IDE 缺陷而造成脚本编写效率的降低。

 

下面介绍一种方法,通过 WSC 封装 VBS 脚本,注册成 COM 对象,然后添加到 QTP 保留对象注册表中,从而实现在 QTP IntelliSense 访问。

 

1 )创建 WSC 文件

<?xml version="1.0"?>

<component>

 

<?component error="true" debug="true"?>

<reference object="Scripting.Dictionary" />

<registration description="Functions" progid="QTP.Functions" version="1.00" classid="{d 7c 40957-00d4 -41a 5-a87b-89d1db311423}">

</registration>

 

<public>

<method name="SetID" internalName="SetID" dispid="0">

       <parameter name="sValue"/>

</method>

<method name="GetID">

</method>

<method name="PrintMessage">

       <parameter name="strMessage"/>

</method>

</public>

 

<script language = "VBScript">

<![CDATA[

       Dim pID

       Function GetID()

              GetID = pID

       End Function

       Function SetID(sValue)

              pID = sValue

       End Function

       Function PrintMessage(strMessage)

              Msgbox strMessage

       End Function

       ]]>

</script>

 

</component>

2 )注册 WSC 文件

选中 WSC 文件,单击鼠标右键,选择“注册”

或者运行“ regsvr32  "D:/QTP/MyWork/IntelliSenseTest1/test.wsc" ”命令进行注册

 

3 )注册到 QTP

打开注册表,添加“ Functions ”项,以及 ProgID UIName

 

4 )在 QTP 中使用 IntelliSense

重新启动 QTP 后就可以使用 WSC 文件中定义的函数。在专家视图中就可以使用“ Functions ”的 IntelliSense 功能,输入“ Functions ”加点号后,就会自动弹出其所有可用的属性和方法。

 

 

参考:

http://www.advancedqtp.com/knowledge-base/articles/qtp-tricks4/qtp-hacks/intellisense-and-com/

 

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值