51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1920|回复: 1
打印 上一主题 下一主题

[原创] 利用Mercury.ObjectRepositoryUtil遍历对象库对象,出现,stopped working

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2011-9-29 11:37:39 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
创建vbs脚本如下:
on error resume  next
Dim ImageObj, PageObj, RepositoryFrom, RepositoryTo
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
tsrPath="c:\查询.tsr"
RepositoryFrom.Load tsrPath
call  EnumerateAllChildProperties(Root)
Set RepositoryFrom =nothing
msgbox "lixudong"
Function EnumerateAllChildProperties(Root)
    Dim TOCollection, TestObject,Msg
    Set TOCollection = RepositoryFrom.GetChildren(Root)
    For i = 0 To TOCollection.Count - 1
            Set TestObject = TOCollection.Item(i)
            Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine
            msgbox  Msg
            Set  TestObject=nothing
   Next
            Set TOCollection=nothing
End Function

执行这段代码后,界面出现stopped working异常,请问原因,这个代码我没有发现任何异常啊,请高手指点,谢谢!!!
C:\Users\lixudong\Desktop\12.png
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2011-9-29 16:02:33 | 只看该作者
我试了一下你的代码,把文件名改成英文就好了!没有出现你说的问题!

Dim ImageObj, PageObj, RepositoryFrom
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
tsrPath="c:\QTPTesting.tsr"
RepositoryFrom.Load tsrPath

下面是Help里面的东西,仅供参考:
'The following example retrieves an object repository's objects and properties,

'looks for specific test objects using several methods, and copies a test object

'to another object repository.





Dim ImageObj, PageObj, RepositoryFrom, RepositoryTo



Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")

Set RepositoryTo = CreateObject("Mercury.ObjectRepositoryUtil")



RepositoryFrom.Load "C:\QuickTest\Tests\Flights.tsr"

RepositoryTo.Load "E:\Temp\Tests\Default.tsr"





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, Property, Msg



    Set TOCollection = RepositoryFrom.GetChildren(Root)



    For i = 0 To TOCollection.Count - 1

            Set TestObject = TOCollection.Item(i)

            Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine

            Set PropertiesCollection = TestObject.GetTOProperties()



            For n = 0 To PropertiesCollection.Count - 1

                Set Property = PropertiesCollection.Item(n)

                Msg = Msg & Property.Name & "-" & Property.Value & vbNewLine

            Next

            MsgBox Msg



EnumerateAllChildProperties TestObject

    Next



End Function



Function EnumerateAllObjectsProperties(Root)

'The following function enumerates all the test objects under a specified object.

'For each test object, a message box opens containing the test object's name,

'properties, and property values.

Dim TOCollection, TestObject, PropertiesCollection, Property, Msg



    Set TOCollection = RepositoryFrom.GetAllObjects(Root)



    For i = 0 To TOCollection.Count - 1

        Set TestObject = TOCollection.Item(i)

                    Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine



            Set PropertiesCollection = TestObject.GetTOProperties()

            For n = 0 To PropertiesCollection.Count - 1

                Set Property = PropertiesCollection.Item(n)

                Msg = Property.Name & "-" & Property.Value & vbNewLine

            Next



        MsgBox Msg

    Next



End Function
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-7 21:09 , Processed in 0.086803 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表