用ObjectRepositoryUtil动态加载和解析QTP对象库文件

' 动态加载对象库文件,动态解析出对象来使用

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

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值