使用Object Repository Automation Objects and Methods操作对象库(转)
上一篇 /
下一篇 2009-05-06 13:39:22
/ 个人分类:自动化测试QTP
文章转自(般若菠萝蜜的博客)
Dim RepositoryFrom,TOCollection
Set RepositoryFrom = CreateObject("Mercury.ObjectRepositoryUtil")
RepositoryFrom.Load "C:\Login.tsr"
Set TOCollection = RepositoryFrom.GetAllObjectsByClass("WinButton")
Msgbox TOCollection.Count
具体可参照help文档中关于ObjectRepositoryUtil的应用.
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) |
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 |
EnumerateAllChildProperties TestObject |
FunctionEnumerateAllObjectsProperties(Root) |
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 |
FunctionRenameAllImages(Root) |
DimTOCollection, TestObject, PropertiesCollection,Property |
SetTOCollection = RepositoryTo.GetAllObjectsByClass("Image") |
Fori = 0ToTOCollection.Count - 1 |
SetTestObject = TOCollection.Item(i) |
RepositoryTo.RenameObject (TestObject,"Image "& i) |
RepositoryTo.UpdateObject TestObject |
FunctionRemoveAllLinks(Root) |
DimTOCollection, TestObject, PropertiesCollection,Property |
SetTOCollection = RepositoryFrom.GetChildren(Root) |
Fori = 0ToTOCollection.Count - 1 |
SetTestObject = TOCollection.Item(i) |
TOClass = TestObject.GetTOProperty("micclass") |
RepositoryFrom.RemoveObject Root, TestObject |
EnumerateAllChildProperties TestObject |
CallEnumerateAllChildProperties(Null) |
CallEnumerateAllObjectsProperties(Null) |
CallRenameAllImages(Null) |
SetImageObj = RepositoryFrom.GetObject("Browser(""CNN.com"").Page(""CNN.com"").Image(""Remains identified"")") |
If(NotIsNull(ImageObj))Then |
MsgBox RepositoryFrom.GetLogicalName(ImageObj) |
SetPageObj = RepositoryTo.GetObjectByParent("Browser(""CNN.com"")","Page(""CNN.com"")") |
If(NotIsNull(PageObj))Then |
MsgBox RepositoryTo.GetLogicalName(PageObj) |
RepositoryTo.AddObject ImageObj, PageObj |
收藏
举报
TAG: