如何根据对象名找出对象库中完整路径的对象
上一篇 / 下一篇 2008-11-06 01:01:28 / 个人分类:QTP
Dim MyArray()
Dim RowNumber
RowNumber = 100
ReDim MyArray(2, RowNumber)
Dim RowCount
Set RootObj = CreateObject("Mercury.ObjectRepositoryUtil")
RootObj.Load "E:\Project\QTPTest\test.tsr"
RowCount = 0
EnumberateRepository(NULL)
7Q.o1q%E-Y0If RowCount < UBound(MyArray, 2) Then51Testing软件测试网\gXn5M
ReDim Preserve MyArray(2, RowCount-1)
c^k:kF0g n\s|0End If
U o!wo'u{3f Ne\0Execute GetobjectDescrīption("q")&".Set "&"""Randall"""
Set RootObj = Nothing
'***************************************************************************************
Sub EnumberateRepository(Root)
lEr Uou c5b{0 Dim TOCollection, TestObject, PropertiesCollection
v/[FJ IP)t0 Set TOCollection = RootObj.GetChildren(Root)51Testing软件测试网 a?!QjN3?\%Z]6S
If RowCount > Ubound(MyArray, 2) Then
%QIf3du0 ReDim Preserve MyArray(2, Ubound(MyArray, 2) + 100)
?3qD7aet Po0 End If
9fLb`]2h'GmI0 For i = 0 To TOCollection.Count - 1
g)B;aO8W.K2?]D V0 Set TestObject = TOCollection.Item(i)51Testing软件测试网_@2s urL| h LE
MyArray(0, RowCount) = TestObject.GetToProperty("MicClass")
$Vs%jZ@y ^3Z Z!o0 MyArray(1, RowCount) = RootObj.GetLogicalName(TestObject)51Testing软件测试网N2fkAJ$Z;P%h
If IsNull(Root) Then
$V^bbgc0 MyArray(2, RowCount) = ""
yCP m|.iR5E0 Else 51Testing软件测试网uqt4}B;Q k5A
MyArray(2, RowCount) = RootObj.GetLogicalName(Root)
/qQy7Zlu8cn$B0 End If
L QOY?;e;@%W:D&Y0 RowCount = RowCount +151Testing软件测试网%rf$?A1o:t
EnumberateRepository TestObject
M.yc5[ M @zf-P [0 Next
N} f7}v&T6?vU"w0End Sub
'***************************************************************************************
Function GetobjectDescrīption(objname)
2jw!E&WnQ_;?vD0Dim ObjDescrīption, ParentName
hX_%z,]6nE3u0ObjDescrīption = ""
#l.`$lBb0i = UBound(MyArray, 2)51Testing软件测试网/o;Zf(c9mu"S
ParentName = objname51Testing软件测试网5pi"Z:X8Uo.[
While i >= 051Testing软件测试网Jj/z9|Tt2U4d
If StrComp(myarray(1, i), ParentName) = 0 Then51Testing软件测试网9b8E$e(V6]aWu
ParentName = myarray(2, i)51Testing软件测试网T&\?&[T_;{)L3n
If StrComp(ObjDescrīption, "") = 0 then51Testing软件测试网%_6|iHT5e&yW'P$p(W2N
ōbjDescrīption = MyArray(0, i)&"("&chr(34)&MyArray(1, i)&chr(34)&")"
5X&i6o