问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/30164977/programmatically-add-object-to-qtp-local-repository