使用QuickTest Pro获取质量中心API接口ISupportCopyPaste的引用
Quality Center OTA API 提供了一些接口,比如 ISupportCopyPaste(可以使用剪贴板来复制/粘贴数据)。获取一个已实现接口的参考的文档方法是:
'Declare a variable to hold the reference for the interface
Dim bf As IBaseFactory2
' By assigning the implementing object reference to the
' IBaseFactory2 type variable, the type is cast to that of the
' implemented interface. The new variable is a reference to the
' IBaseFactory2 interface within the parent object.
' tdc is the global TDConnection object.
Set bf = tdc.BugFactory
上面的代码是用 VB 写的(我不想用这个)。
不过,QTP 在 Dim 语句中不允许使用 'As'。
有没有人能告诉我如何在 QTP 中获取一个参考?
有没有其他解决这个问题的方法?比如使用 Python 的 Win32 库。
2 个回答
0
理论上,大多数OTA暴露的对象和它们提供的接口都是IDispatch。
换句话说;当你在vbscript中使用这些对象时,其实不需要把手头的对象转换成ISupportCopyPaste。你可以直接像使用ISupportCopyPaste那样调用这些对象的方法,只要确保方法的格式正确就可以了。
2
QTP不允许在Dim
语句中使用As
的原因是,QTP脚本是基于VBScript的,而不是VB。VBScript是动态类型的,而As
这个用法只在VB中存在。
如果你想在QTP中使用OTA,可以尝试使用QTP提供的QCUtil
对象(更多信息可以查看QTP的帮助文档)。
如果QCUtil
没有提供你需要的对象,你可以使用任何能够与COM交互的语言来创建OTA对象(这些语言包括但不限于VB、VBScript、C++和.NET语言,至于Python我就不太确定了)。
如果你选择使用VBScript,可以通过VBScript的CreateObject
函数来创建OTA对象(想了解更多信息,可以搜索CreateObject OTA)。