用心做人,用心做事!

Manipulate Object Repositories

上一篇 / 下一篇  2009-10-14 11:57:32 / 个人分类:QTP

'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.
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"

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

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

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

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

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)
 Else: MsgBox"null"
EndIf
SetPageObj = RepositoryTo.GetObjectByParent("Browser(""CNN.com"")","Page(""CNN.com"")")
If(NotIsNull(PageObj))Then
 MsgBox RepositoryTo.GetLogicalName(PageObj)
 Else: MsgBox"null"
EndIf
RepositoryTo.AddObject ImageObj, PageObj
RepositoryFrom.Save
RepositoryTo.Save

TAG:

 

评分:0

我来说两句

Open Toolbar