' 动态加载对象库文件,动态解析出对象来使用
Dim ObjectRepository
Set ObjectRepository = CreateObject("Mercury.ObjectRepositoryUtil")
'ObjectRepository.ImportFromXML "C:\Documents and Settings\allen\桌面\TestOR\OR.xml", "C:\Documents and Settings\allen\桌面\TestOR\OR\NewOR.tsr"'
ObjectRepository.Load "C:\Documents and Settings\allen\桌面\TestOR\OR\NewOR.tsr"
'ObjectRepository.Load "C:\Documents and Settings\allen\桌面\TestOR\OR\OR.xml"
'EnumerateAllChildProperties("")
FindObject "Login"
Set ObjectRepository = Nothing
'-------------------------------------------------------------------------
Function FindObject( ObjectName )
Dim TOCollection
Set TOCollection = ObjectRepository.GetAllObjects()
For i = 0 to TOCollection.Count -1
Set TestObject = TOCollection.Item(i)
'Print ObjectRepository.GetLogicalName ( TestObject )
If ObjectRepository.GetLogicalName ( TestObject ) = ObjectName Then
Set PropertiesCollection = TestObject.GetTOProperties()
For n = 0 To PropertiesCollection.Count - 1
Set ObjectProperty = PropertiesCollection.Item(n)
If ObjectProperty.Name = "text" Then
Dialog("text:=" & ObjectProperty.Value).Activate ' 动态解析对象, 拼凑成测试脚本执行
End If
Next
End If
Next
End Function
'----------------------------------------------------------------------------------
Function EnumerateAllChildProperties(Root)
'The following function recursively enumerates all the test objects directly under
'a specified parent object. For each test object, a message box opens containing the
'test object's name, properties, and property values.
Dim TOCollection, TestObject, PropertiesCollection, ObjectProperty, Msg
Set TOCollection = ObjectRepository.GetChildren(Root)
For i = 0 To TOCollection.Count - 1
Set TestObject = TOCollection.Item(i)
Msg = ObjectRepository.GetLogicalName(TestObject) & vbNewLine
Set PropertiesCollection = TestObject.GetTOProperties()
For n = 0 To PropertiesCollection.Count - 1
Set ObjectProperty = PropertiesCollection.Item(n)
Msg = Msg & ObjectProperty.Name & "-" & ObjectProperty.Value & vbNewLine
Next
MsgBox Msg
EnumerateAllChildProperties TestObject
Next
End Function