共同探讨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)
51Testing软件测试网:{EV/{	Pef
g
If RowCount < UBound(MyArray, 2) Then51Testing软件测试网#e4Zp6{0{%a ^
 ReDim Preserve MyArray(2, RowCount-1)
)We1o|f3sm0End If
51Testing软件测试网B6Pp9wHDnt;g
Execute GetobjectDescrīption("q")&".Set "&"""Randall"""
Set RootObj = Nothing
'***************************************************************************************
Sub EnumberateRepository(Root)
``eBr6zb0    Dim TOCollection, TestObject, PropertiesCollection51Testing软件测试网 m9D;P(R \#o`.}P$G8oU
    Set TOCollection = RootObj.GetChildren(Root)51Testing软件测试网%qIj+s%}/?Y2~%x D0H
 If RowCount > Ubound(MyArray, 2) Then51Testing软件测试网L4FV+DU4c
  ReDim Preserve MyArray(2, Ubound(MyArray, 2) + 100)
)P9]1j s0vkb0 End If51Testing软件测试网m;A8^Y-v
    For i = 0 To TOCollection.Count - 151Testing软件测试网 K6o\XV:Ze']
            Set TestObject = TOCollection.Item(i)51Testing软件测试网P o$tZRI9j^i
   MyArray(0, RowCount) = TestObject.GetToProperty("MicClass")51Testing软件测试网8|)[th B#Qj/q
   MyArray(1, RowCount) = RootObj.GetLogicalName(TestObject)51Testing软件测试网m_tcb`!Wo
   If IsNull(Root) Then
&ce3vs.i0    MyArray(2, RowCount) = ""51Testing软件测试网^(X}G@
   Else  
Y.q0gf};Kz*W#\Tk0    MyArray(2, RowCount) = RootObj.GetLogicalName(Root)
U!G!l.KnV Bo%u0   End If   
XN/hi0?dP'q3o0  RowCount = RowCount +151Testing软件测试网|*L p?HNSkZ
     EnumberateRepository TestObject  51Testing软件测试网Z8GZ MaX
     Next 
O\n9a w S8q"}DD%w)m0End Sub
'***************************************************************************************
Function GetobjectDescrīption(objname)
m kVv,Dpx Zf_0Dim ObjDescrīption, ParentName51Testing软件测试网3sJ8r!h9Fs/[L} YH
ObjDescrīption = ""
H SM,M|a g0i = UBound(MyArray, 2)51Testing软件测试网4O.T!~8?y\5r7r
ParentName = objname51Testing软件测试网 ^Kwwc?@*hw
While i >= 051Testing软件测试网xU!v/@&DnD'y
If StrComp(myarray(1, i), ParentName) = 0 Then51Testing软件测试网 K%Zp"`qVx
    ParentName = myarray(2, i)51Testing软件测试网X.|w7j"Nnn
    If StrComp(ObjDescrīption, "") = 0 then
^1YkfdI W0}8f0    ōbjDescrīption = MyArray(0, i)&"("&chr(34)&MyArray(1, i)&chr(34)&")"
8d4cy G6G!_$_H3i0    Else
vl"g*j8~B3D&h6t/M0    ōbjDescrīption = MyArray(0, i)&"("&chr(34)&MyArray(1, i)&chr(34)&")"&"."&ObjDescrīption
ia U6B%C6a nY0 End If51Testing软件测试网"H'@u8r5x/iJN3z
 If StrComp(myarray(2, i), "") = 0 Then51Testing软件测试网q0R&~ y&N8t2N#a
 GetobjectDescrīption = ObjDescrīption51Testing软件测试网9kiPP-H
 Exit Function
7O vW+{1ZC,s0 End If 51Testing软件测试网-K ?-G{ x8w
End If 
I$Sf%ba.e$@2K _0i = i - 151Testing软件测试网Wvx8~s ZXO
Wend
?%n4T Y uCt2F0End Function51Testing软件测试网&mwdI1U"mn

TAG: QTP

 

评分:0

我来说两句

Open Toolbar