共同探讨QTP相关问题

使用Object Repository Automation Objects and Methods操作对象库

上一篇 / 下一篇  2008-07-13 11:39:58 / 个人分类:QTP

51Testing软件测试网/o-gy]!U{

Dim RepositoryFrom,TOCollection51Testing软件测试网hW&|ZD-v
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
F0n;^e Kha0RepositoryFrom.Load "C:\Login.tsr"51Testing软件测试网 }at#@8ho)r/v
Set TOCollection = RepositoryFrom.GetAllObjectsByClass("WinButton")51Testing软件测试网 KOVNO*E
Msgbox TOCollection.Count51Testing软件测试网V"[ g*R{+x

b3zDVT _8s051Testing软件测试网]@&yv5}9S0]

具体可参照help文档中关于ObjectRepositoryUtil的应用.51Testing软件测试网b a:S,n-W"`iS

51Testing软件测试网t@d7R mI r

'The following example retrieves an object repository's objects and properties,

8}'FK]0_0
'looks for specific test objects using several methods, and copies a test object
'to another object repository.
DimImageObj, PageObj, RepositoryFrom, RepositoryTo
SetRepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
SetRepositoryTo = CreateObject("Mercury.ObjectRepositoryUtil")
RepositoryFrom.Load"C:\QuickTest\Tests\Flights.tsr"
RepositoryTo.Load"E:\Temp\Tests\Default.tsr"

0IzyBFn1Jb&s)Y[051Testing软件测试网9lu;\x%a
 

8N6P W}pIs0
FunctionEnumerateAllChildProperties(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.
    DimTOCollection, TestObject, PropertiesCollection,Property, Msg
    SetTOCollection = RepositoryFrom.GetChildren(Root)
    Fori = 0ToTOCollection.Count - 1
            SetTestObject = TOCollection.Item(i)
            Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine
            SetPropertiesCollection = TestObject.GetTOProperties()
            Forn = 0ToPropertiesCollection.Count - 1
                SetProperty= PropertiesCollection.Item(n)
                Msg = Msg &Property.Name &"-"&Property.Value & vbNewLine
            Next
            MsgBox Msg
EnumerateAllChildProperties TestObject
    Next
EndFunction

)e"_5Y_zpbz*l0
!C'}]U)b0 51Testing软件测试网dYMC1QG6b2z^

FunctionEnumerateAllObjectsProperties(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.
 DimTOCollection, TestObject, PropertiesCollection,Property, Msg
    SetTOCollection = RepositoryFrom.GetAllObjects(Root)
    Fori = 0ToTOCollection.Count - 1
        SetTestObject = TOCollection.Item(i)
                    Msg = RepositoryFrom.GetLogicalName(TestObject) & vbNewLine
            SetPropertiesCollection = TestObject.GetTOProperties()
            Forn = 0ToPropertiesCollection.Count - 1
                SetProperty= PropertiesCollection.Item(n)
                Msg =Property.Name &"-"&Property.Value & vbNewLine
            Next
        MsgBox Msg
    Next
EndFunction
51Testing软件测试网 A9xL7hI&}2E;]a


)X6| qw5_4B0 51Testing软件测试网+wh;_0L_

FunctionRenameAllImages(Root)
'The following function sets a new name for all image test objects under a specified object.
 DimTOCollection, TestObject, PropertiesCollection,Property
    SetTOCollection = RepositoryTo.GetAllObjectsByClass("Image")
    Fori = 0ToTOCollection.Count - 1
            SetTestObject = TOCollection.Item(i)
            RepositoryTo.RenameObject (TestObject,"Image "& i)
            RepositoryTo.UpdateObject TestObject
    Next
EndFunction
51Testing软件测试网 LM)}*rSD

51Testing软件测试网A u R1as/}:K&@
 

{0O*]9rOb[ ]Ot g'A0
FunctionRemoveAllLinks(Root)
'The following function recursively enumerates all the test objects under a specified object.
'It looks for all test objects of class Link and removes them from their parent objects.
    DimTOCollection, TestObject, PropertiesCollection,Property
    SetTOCollection = RepositoryFrom.GetChildren(Root)
    Fori = 0ToTOCollection.Count - 1
            SetTestObject = TOCollection.Item(i)
            TOClass = TestObject.GetTOProperty("micclass")
         IfTOClass ="Link"Then
                RepositoryFrom.RemoveObject Root, TestObject
            EndIf
        EnumerateAllChildProperties TestObject
    Next
EndFunction
51Testing软件测试网"lSj+I6E1We

51Testing软件测试网r!n[ h%Q
 51Testing软件测试网v5L/a"w1yLAn

CallEnumerateAllChildProperties(Null)
CallEnumerateAllObjectsProperties(Null)
CallRenameAllImages(Null)
CallRemoveAllLinks(Null)
SetImageObj = RepositoryFrom.GetObject("Browser(""CNN.com"").Page(""CNN.com"").Image(""Remains identified"")")
If(NotIsNull(ImageObj))Then
 MsgBox RepositoryFrom.GetLogicalName(ImageObj)
 ElseMsgBox"null"
EndIf
SetPageObj = RepositoryTo.GetObjectByParent("Browser(""CNN.com"")","Page(""CNN.com"")")
If(NotIsNull(PageObj))Then
 MsgBox RepositoryTo.GetLogicalName(PageObj)
 ElseMsgBox"null"
EndIf
RepositoryTo.AddObject ImageObj, PageObj
RepositoryFrom.Save
RepositoryTo.Save

TAG: QTP

 

评分:0

我来说两句

Open Toolbar