QTP OR自动化模型:向QTP对象存储库添加多个对象(相同类型)

时间:2015-06-03 07:29:45

标签: qtp

我使用以下代码:

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

没有将两个对象(" OrderNum1"," OrderNum2")添加到QTP OR,只添加了第一个。

1 个答案:

答案 0 :(得分:2)

问题是你要两次添加同一个对象。如果出现相同的对象,QTP的对象存储库将被设置为重用现有对象。 您应该为对象添加一些描述性属性,以使其不同。

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