问题
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