• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

软件测试工具QTP基础代码收集

发布: 2010-5-12 17:48 | 作者: 网络转载 | 来源: 领测软件测试 | 查看: 281次 | 进入软件测试论坛讨论

领测软件测试网

5、WebTable功能函数集合:

' ************************************************** Function Library ********************************
   
  ' Registering both functions
  RegisterUserFunc "WebTable", "ObjectsByMicClass", "ObjectsByMicClass"
  RegisterUserFunc "WebTable", "ItemByKeyColumn", "ItemByKeyColumn"
   
  ' Function: ObjectsByMicClass
  ' Descrīption: Returns a collection of objects all the objects in a
  ' WebTable that have the specified MicClass
  ' Return Value: A Collection of Objects
  ' Arguments:
  ' Obj - Test Object (WebTable)
  ' micClass - The micClass of the objects to retrieve
  '-----------------------------------------------------------------------------------------------------------
  Function ObjectsByMicClass(Obj, micClass)
  Set Table = Obj
  ' Create a collection object to hold the items
  Set ōbjCollection = CreateObject("scrīpting.Dictionary")
  ' Go over all the cells in the table, and look for objects with the specified micClass
  For row=1 to Table.RowCount
  ColumnCount=Table.ColumnCount(row)
  For col=1 to ColumnCount
  For ItemIndex=0 to Table.ChildItemCount(row, col, micClass)-1
  Set childItem=Nothing
  Set childItem = Table.ChildItem(row, col, micClass, ItemIndex)
  If Not childItem is Nothing Then
  ' If the cell contains a micClass object, add it to the collection
  ItemKey = objCollection.Count + 1
  objCollection.Add ItemKey, childItem
  End if
  Next
  Next
  Next
  Set ōbjectsbyMicClass = objCollection
  End Function
 
 
  ' Function: ItemByKeyColumn
  ' Descrīption: Returns an item from a column, based on the value of a
  ' key column
  ' Return Value: Object
  ' Arguments:
  ' Obj - Test Object (WebTable)
  ' KeyColumnIndex - Index of the KeyColumn
  ' KeyColumnValue - Value to search for in the key column
  ' KeyItemIndex - Index of the value in the key column (if there is
  '                        more than one). If 0, the first item will be used.
  ' TargetColumnIndex - Column from which to retrieve the target item
  ' micClass - The micClass of the target item
  ' TargetItemIndex - Index of the target item to retrieve (if there is
  '                           more than one). If 0, the first item will be used.
  ' ------------------------------------------------------------------------------------------------------------------------------------
  Function ItemByKeyColumn(Obj, KeyColumnIndex, KeyColumnValue, KeyItemIndex, TargetColumnIndex, micClass, TargetItemIndex)
  Table = Obj
  rowCount = Table.RowCount
 
  ' if TargetItemIndex was not specified, use 1 as deafult
  If TargetItemIndex < 1 Then
  TargetItemIndex = 1
  End If
  ' if KeyColumnIndex was not specified, use 1 as default
  If KeyItemIndex < 1 Then
  KeyItemIndex = 1
  End If
 
  ' look for KeyColumnValue in the key column to determine which
  ' row to retrieve the targe item from
  Row = 0
  foundIndex = 0
  While Row <= RowCount And foundIndex < KeyItemIndex
  Row = Row + 1
  CellData = Table.GetCellData(Row, KeyColumnIndex)
  If CellData = KeyColumnValue Then
  foundIndex = foundIndex + 1
  End If
  Wend
  If foundIndex < KeyItemIndex Then
  Exit Function
  End If
 
  ' Now that we know the row, retrieve the item (according to its micClass)
  ' from the target column.
  ChildItemsCount = Table.ChildItemCount(Row, TargetColumnIndex, micClass)
  If ChildItemsCount > =1 And ChildItemsCount >= TargetItemIndex Then
  Set GetItemByKeyColumn = Table.ChildItem(Row, TargetColumnIndex, micClass, TargetItemIndex-1)
  End If
  End Function
 
 
  ' ************************************ Examples that use these functions *******************************************************
 
 
  ' Using the ItemByKeyColumn Function
  Set ōbj = Browser("Table with objects").Page("Itenerary: Mercury Tours").WebTable("Acapulco to Zurich").ItemByKeyColumn(1,"FLIGHT",2,3,"WebElement",1)
  msgbox obj.GetROProperty("innerhtml")
 
  ' Using the ObjectsByMicClass function
  Set collection = Browser("Browser").Page("Page").WebTable("Table").ObjectsByMicClass("WebCheckBox")
  For i=1 to collection.count
  If collection(i).GetROProperty("checked") Then
  collection(i).Set "OFF"
  Else
  collection(i).Set "ON"
  End If
  Next

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/

33/3<123

关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网