以编程方式将对象添加到 qtp 本地存储库

programmatically add object to qtp local repository

我正在研究视觉关系标识符 (VRI) QTP,当我在对象 repository.But 中添加源对象(参见代码)时它工作正常,在 QTP 帮助文件中提到: "The specified object must be an object from the test object repository. It cannot be a test object specified by a programmatic description."

我使用的代码是:

Set rc = VisualRelations.Create
Set relation = rc.Add   

'****(Source Object)
relation.relatedobjectpath = "Browser(""Oracle | PeopleSoft Enterprise"").Page(""Oracle | PeopleSoft Enterprise"").WebElement(""User ID:"")"

relation.relativeposition = micRelLeft
relation.setargument micrelinline, True

Set des=Description.Create
des.Add "micclass","WebEdit"
des.Add "visual relations",rc   

'****(Target Object)
Browser("name:=Oracle.*").Page("title:=Oracle.*").WebEdit(des).set "qtpuser@abc.com"
Set relation = Nothing
Set rc = Nothing

有什么办法可以避免对象库的依赖。如果没有,是否可以将源对象动态加载到对象存储库中,并可以用于 VRI?

谢谢和问候,

Sreenisha Sreenivasan

是的,这可以做到,为此有一个API,请参阅联机帮助中的"HP QuickTest Professional Object Repository Automation Reference"。

但是,您不能轻易地向已加载的 OR 添加新对象。 引用上面的 dox,这(几乎)全部说明了:

Note: You can use the Object Repository automation object model to manipulate shared object repositories saved in the file system. If you want to manipulate a shared object repository stored in Quality Center, you must download the shared object repository and save it to the file system, before using the Object Repository automation object model to manipulate it.

这也意味着您需要下载(或找到)tsr 文件,使用 API 对其进行操作,卸载当前加载的 OR,然后重新加载它们。我发现创建一个简单的测试对象太麻烦了。

因此,事实证明以下解决方法很有用:

  • 使用 OR 编辑器为 "anchor" 对象准备一个 "template" OR 条目 class。
  • 确保它包含您要控制的所有 TO 属性,并将它们设置为任意值。
  • 同时准备视觉关系依赖于那个测试对象。当然,当您尝试从 OR 编辑器中查找测试对象时,这种视觉关系将不起作用。
  • 然后在运行时,使用 .setTOProperty 以编程方式修改该测试对象的 TO 属性,以便将其属性设置为您在该实际情况下需要期望的值。

即使 "anchor" 测试对象的 TO 属性值在 "compile" 时尚未固定,并且不使用相当复杂的 OR API,视觉关系也会起作用, 并且没有 unloading/reloaded OR 文件。**

作为旁注,由于视觉关系的严重局限性,请考虑完全避免使用它们。迟早你希望视觉关系依赖于 "anchor" 本身取决于视觉关系的测试对象(不可能——严重的限制,我看不出原因),迟早你会厌倦我概述的解决方案,因为它的间接性质(这让你回到你原来的问题)。

另一种方法是创建脚本代码来执行与视觉关系 等效的操作,即获取 "anchor" 测试对象的 x and/or y 位置,并创建使用描述性编程,通过 Description 对象,或通过使用 .ChildObjects 和一些枚举候选对象,通过 "guessing" 其 x/y 位置(或其他属性)对相关对象的描述代码。

这与一些智能基础库例程设计一起,创建了紧凑、可维护、可读的解决方案,没有 OR 依赖性,并且没有视觉关系功能固有的限制。