|
'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:\Program Files\Mercury Interactive\QuickTest Professional\CodeSamplesPlus\Flight_Samples\SOR.tsr"
RepositoryTo.Load "C:\Program Files\Mercury Interactive\QuickTest Professional\dat\BPT_Resources\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
Function RenameAllImages(Root)
'The following function sets a new name for all image test objects under a specified object.
Dim TOCollection, TestObject, PropertiesCollection, Property
Set TOCollection = RepositoryTo.GetAllObjectsByClass("Image")
For i = 0 To TOCollection.Count - 1
Set TestObject = TOCollection.Item(i)
RepositoryTo.RenameObject (TestObject ("Image ") & i )
RepositoryTo.UpdateObject TestObject
Next
End Function
Function RemoveAllLinks(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.
Dim TOCollection, TestObject, PropertiesCollection, Property
Set TOCollection = RepositoryFrom.GetChildren(Root)
For i = 0 To TOCollection.Count - 1
Set TestObject = TOCollection.Item(i)
TOClass = TestObject.GetTOProperty("micclass")
If TOClass = "Link" Then
RepositoryFrom.RemoveObject Root, TestObject
End If
EnumerateAllChildProperties TestObject
Next
End Function
Call EnumerateAllChildProperties(Null)
Call EnumerateAllObjectsProperties(Null)
Call RenameAllImages(Null)
Call RemoveAllLinks(Null)
Set ImageObj = RepositoryFrom.GetObject("Browser(""CNN.com"").Page(""CNN.com"").Image(""Remains identified"")")
If (Not IsNull(ImageObj)) Then
MsgBox RepositoryFrom.GetLogicalName(ImageObj)
Else: MsgBox "null"
End If
Set PageObj = RepositoryTo.GetObjectByParent("Browser(""CNN.com"")", "Page(""CNN.com"")")
If (Not IsNull(PageObj)) Then
MsgBox RepositoryTo.GetLogicalName(PageObj)
Else: MsgBox "null"
End If
RepositoryTo.AddObject ImageObj, PageObj
RepositoryFrom.Save
RepositoryTo.Save
请问各位这个脚本是做什么用的,感觉好象是两个脚本进行比较,但不知道是不是,请各位大大给点提示,小第先谢谢了 |
|