共同探讨QTP相关问题

如何根据对象名找出对象库中完整路径的对象

上一篇 / 下一篇  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软件测试网\g Xn5M
 ReDim Preserve MyArray(2, RowCount-1)
c^ k:kF0g n\s|0End If

Uo!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
9f Lb ` ]2h'GmI0    For i = 0 To TOCollection.Count - 1
g)B;aO8W.K2?] D V0            Set TestObject = TOCollection.Item(i)51Testing软件测试网_@2su rL| hLE
   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)
/qQ y7Zlu8cn$B0   End If   
L QO Y?;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] aW u
    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&i6oz~(Vs6~K0    Else51Testing软件测试网!r Fz"F G~)E
    ōbjDescrīption = MyArray(0, i)&"("&chr(34)&MyArray(1, i)&chr(34)&")"&"."&ObjDescrīption
rI#~#m]+Q8{ Z6g0 End If
u,PG,F[r9E R0 If StrComp(myarray(2, i), "") = 0 Then
V[Qyp{ G9K }2r+o0 GetobjectDescrīption = ObjDescrīption51Testing软件测试网9n)FpV_/G
 Exit Function
aA V P:t4V{%P0 End If 51Testing软件测试网\3l`0S)f'OQS@
End If 51Testing软件测试网;h$H,QZ$Z N
i = i - 151Testing软件测试网K"hjB%|zL:{4Wr
Wend
)^+hz7@2h4HbQ Q X0End Function
9wcC\Y0

TAG: QTP

 

评分:0

我来说两句

Open Toolbar