How to add objects to object repository automatically using vb scripts?

☆樱花仙子☆ 提交于 2019-12-13 19:52:34

问题


Is it possible to add objects to an object repository automatically using VBScript?

Let's say I have list of links in my webpage/application. It would be time consuming, when I add objects manually so I tried to add objects to repository automatically. But couldn't able to proceed as I don't know how to activate object repository (during run time) in QTP.

Below is my code which I tried:

Function Objects_Count(myObject)
  Dim Objects
  Set Objects=Description.Create
  Objects("micclass").value=myObject
  set obj=Browser("title:=.*").Page("title:=.*").ChildObjects(Objects)
  For i=0 to obj.count-1
    'msgbox i
    c=obj(i).getroproperty("name")
    If obj(i).Exist(1) Then
      obj(i).highlight
    End If
    Print c
  Next
End Function
Call Objects_Count("link")

The above code will get the links name displayed in a log file and also it will highlight in application/webpage. Please guide me how to add the properties of that links(objects) to object repository.

Thanks!


回答1:


In order to manipulate the object repository, you'll need the Mercury.ObjectRepositoryUtil object, load an existing object repository and add an object to it using AddObject.

Set myRepository = CreateObject("Mercury.ObjectRepositoryUtil")
myRepository.Load "C:\QuickTest\Tests\Flights.tsr"
myRepository.AddObject myLink, Browser("B").Page("P"), "myLinkName"

You'll have to play with it a bit to get it working in your situation. Use the QTP help to find out all accessible methods/properties of the ObjectRepositoryUtil, just enter "ObjectRepositoryUtil" in the search box underneath the Index tab.




回答2:


Edit: You need to create the test object by its ProgId not by its micclass.

Then use SetTOProperty in order to create the relevant description from the values returned by ChildObjects.

See this question for more details.


I don't believe there is a way to add a test object dynamically. ObjectRepositoryUtil.AddObject has this in its documentation:

You can use this method to add a copy of an object that you retrieved from a different object repository.

You can dynamically create a repository via XML with the properties fetched in your test but I think this is more bother than it's worth.

Probably best to use descriptive programming in this case.

For more details see this LinkedIn thread.



来源:https://stackoverflow.com/questions/14813791/how-to-add-objects-to-object-repository-automatically-using-vb-scripts

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!