zoukankan      html  css  js  c++  java
  • QTP的那些事webtable的一些重要使用集合精解

    ' ******************************** Function Library ********************************* 
    
    ' Registering both functions 
    RegisterUserFunc "WebTable", "ObjectsByMicClass", "ObjectsByMicClass" 
    RegisterUserFunc "WebTable", "ItemByKeyColumn", "ItemByKeyColumn" 
    ' 函数功能: ObjectsByMicClass 
    ' 描述: Returns a collection of objects. All the objects in a 
    ' WebTable that have the specified MicClass 得到webtable下面指定的一个micclass类型的元素的所有对象的集合
    ' Return Value: A collection of objects    得到对象的集合
    ' Arguments: 参数无
    ' Obj - Test Object (WebTable) 测试对象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 objCollection = CreateObject("Scripting.Dictionary")    '字典集合,很重要的一个方式,存放的对象可以在action之间传递
        ' Go over all the cells in the table, and look for objects with the specified micClass 
        For row=1 to Table.RowCount   '遍历webtable的所有行
            ColumnCount=Table.ColumnCount(row)      '得到webtable中指定行的列数
            For col=1 to ColumnCount      '遍及指定行的所有的列
                For ItemIndex=0 to Table.ChildItemCount(row, col, micClass)-1   '遍及webtable中指定行,指定列的指定类型对象的个数
                    Set childItem=Nothing 
                    Set childItem = Table.ChildItem(row, col, micClass, ItemIndex)     '获得webtable中指定行,指定列中指定对象类型,加上特定的index的对象
                    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 ObjectsbyMicClass = objCollection   '返回获取到的对象的集合
    End Function 
    '******************************************************
    ' Function: ItemByKeyColumn 
    ' Description: 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) 
        Set Table = Obj 
        rowCount = Table.RowCount    '获得webtable中总计的行数
        ' If TargetItemIndex 没有指定,就采用默认的1
        If TargetItemIndex < 1 Then 
            TargetItemIndex = 1 
        End If 
        ' 如果 KeyColumnIndex没有指定,采用默认的1
        If KeyItemIndex < 1 Then 
            KeyItemIndex = 1 
        End If 
        ' Look for KeyColumnValue in the key column to determine from which 
        ' row to retrieve the target item 
        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 
    
    ' *******************函数使用例子 ****************************** 
    
    ' 使用 ItemByKeyColumn 函数 例子
    Set obj = Browser("Table with objects").Page("Itenerary: Mercury Tours").WebTable("Acapulco to Zurich").ItemByKeyColumn(1,"FLIGHT",2,3,"WebElement",1) 
    msgbox obj.GetROProperty("innerhtml") 
    ' 使用 ObjectsByMicClass 函数例子
    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://seniortesting.club
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

  • 相关阅读:
    【转】ERROR: Cannot uninstall 'llvmlite'. It is a distutils installed project. 此类报错的解决办法
    【转】python setup.py install 报错:error:[WinError 3]系统找不到指定的路径: 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\PlatformSDK\\lib
    【转】距离相关系数以及python包的安装
    【转】算法总结这是一份全面并且详细的排序算法学习指南
    origin 一键导出文件夹中所有图形
    【转】距离相关系数的python实现
    [转]一文让你通俗理解奇异值分解
    origin 检查是否有重复图片
    【Vegas原创】centos网卡自启动
    【Vegas原创】使用dockercompose运行mysql8
  • 原文地址:https://www.cnblogs.com/seniortestingdev/p/2309231.html
Copyright © 2011-2022 走看看