以编程方式将对象添加到 qtp 本地存储库 [英] programmatically add object to qtp local repository

查看:68
本文介绍了以编程方式将对象添加到 qtp 本地存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Visual Relation Identifier (VRI) QTP,当我在对象存储库中添加源对象(见代码)时它工作正常.但是,在 QTP 帮助文件中提到:指定的对象必须是来自测试对象存储库的对象.它不能是由程序描述指定的测试对象."

我使用的代码是:

设置 rc = VisualRelations.Create设置关系 = rc.Add'****(源对象)relation.relatedobjectpath = "Browser(""Oracle | PeopleSoft Enterprise"").Page(""Oracle | PeopleSoft Enterprise"").WebElement(""用户 ID:"")"关系.相对位置 = micRelLeft关系.setargument micrelinline, 真设置 des=Description.Createdes.Add "micclass","WebEdit"des.Add "视觉关系",rc'****(目标对象)Browser("name:=Oracle.*").Page("title:=Oracle.*").WebEdit(des).set "qtpuser@abc.com"设置关系 = 无设置 rc = 无

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

谢谢&问候,

Sreenisha Sreenivasan

解决方案

是的,这可以做到,有一个 API,请参阅在线帮助中的HP QuickTest Professional Object Repository Automation Reference".

强>

但是,您无法轻松地将新对象添加到已加载的 OR. 引用 dox 上面的内容,这(几乎)说明了一切:

<块引用>

注意:您可以使用对象存储库自动化对象模型来操作保存在文件系统中的共享对象存储库.如果你想要操作存储在 Quality 中的共享对象存储库中心,您必须下载共享对象存储库并将其保存到文件系统,在使用对象存储库自动化对象之前模型来操纵它.

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

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

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

即使锚点"测试对象的 TO 属性值在编译"时尚未修复,并且没有使用相当复杂的 OR API,也没有卸载/重新加载 OR 文件,视觉关系也会起作用.**

作为旁注,由于视觉关系的严重限制,请考虑完全避免它们.您迟早会希望视觉关系依赖于本身依赖的锚"测试对象一种视觉关系(不可能——严重的限制,我看不出有什么原因),迟早你会厌倦我概述的解决方案,因为它是间接的(这会让你回到最初的问题).

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

借助一些智能基础库例程设计,可以创建紧凑、可维护、可读的解决方案,没有 OR 依赖性,也没有视觉关系功能固有的限制.

I am working on Visual Relation Identifier (VRI) QTP,it's working fine when i add the source object (see the code) in the object repository.But, in QTP help file it is mentioned that: "The specified object must be an object from the test object repository. It cannot be a test object specified by a programmatic description."

The code I am using is:

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

Is there any way to avoid the dependency of object repository. If not, is it possible to load the source object to object repository dynamically and can be made use for VRI?

Thanks & Regards,

Sreenisha Sreenivasan

解决方案

Yes, this can be done, there is an API for this, see "HP QuickTest Professional Object Repository Automation Reference" in online help.

However, you cannot easily add a new object to the OR already loaded. Quoting from above dox, this says it (almost) all:

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.

This also implies that you´d need to download (or locate) the tsr file, manipulate it using the API, unload the currently loaded ORs, and re-load them. I find this is too much of a hassle just to create a trivial test object.

Thus, the following workaround has proven useful:

  • Prepare a "template" OR entry of the right class for the "anchor" object using the OR editor.
  • Make sure it contains all TO properties you want to control, and set them to any value.
  • Also prepare the visual relation to depend on that test object. Of course this visual relation will not work when you attempt to find the test object from within the OR editor.
  • Then at runtime, programmatically modify that testobject's TO properties using .setTOProperty so its properties are set to the value you need to expect in that actual case.

The visual relation will then work even though the TO properties' values of the "anchor" testobject have not been fixed at "compile" time, and without using the rather complex OR API, and without unloading/reloaded OR files.**

As a side note, because of the serious limitations of visual relations, consider avoiding them altogether. Sooner or later you want a visual relation to depend on an "anchor" test object which itself depends on a visual relation (not possible -- serious limitation which I do not see a reason for), and sooner or later you get sick of the solution I outlined because of its indirect nature (which brings you back to your original question).

An alternative is to create script code doing the equivalent of the visual relation, i.e. fetch x and/or y position of "anchor" testobject, and create a description for the related object by "guessing" its x/y position (or other properties) using descriptive programming, via the Description object, or by enumerating candidate objects using .ChildObjects and some code.

This, with some intelligent base library routine design, creates compact, maintainable, readable solutions without OR dependencies, and without the limitations inherent to the visual relations feature.

这篇关于以编程方式将对象添加到 qtp 本地存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆