QTP OR Automation Model : Adding Multiple objects (Same type) to QTP Object Repository

纵饮孤独 提交于 2019-12-11 04:08:46

问题


I am using the below code:

Set myRepository  = CreateObject("Mercury.ObjectRepositoryUtil")
myRepository.Load  "D:\Explore\QTP\Repositoryfff.tsr"
Set PageObj = myRepository.GetObjectByParent("Browser(""salesforce.com - Customer"")","Page(""salesforce.com - Customer"")")
Set CustomObj = CreateObject("Mercury.WebLink")
myRepository.AddObject CustomObj, PageObj, "OrderNum1"
myRepository.AddObject CustomObj, PageObj, "OrderNum2"
myRepository.Save
Set myRepository = Nothing
Set PageObj = Nothing

It is not adding both of the objects ("OrderNum1","OrderNum2") to the QTP OR, only first one is being added.


回答1:


The problem is that you're adding the same object twice. QTP's object repository is set up to reuse existing objects if an identical object comes along. You should add some descriptive properties to the object so that it's different.

Set myRepository  = CreateObject("Mercury.ObjectRepositoryUtil")
myRepository.Load  "C:\SOR\a.tsr"
Set PageObj = myRepository.GetObjectByParent("Browser(""B"")","Page(""P"")")
Set CustomObj = CreateObject("Mercury.WebLink")
myRepository.AddObject CustomObj, PageObj, "OrderNum1"

' Make objects different
CustomObj.SetTOProperty "name", "second"

myRepository.AddObject CustomObj, PageObj, "OrderNum2"
myRepository.Save
Set myRepository = Nothing
Set PageObj = Nothing


来源:https://stackoverflow.com/questions/30613543/qtp-or-automation-model-adding-multiple-objects-same-type-to-qtp-object-repo

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