QTP成长园地
指定行的数据进行比较
上一篇 /
下一篇 2007-09-26 14:28:11
/ 个人分类:QTP
在录制查询功能或者是添加,修改记录时,需要在列表页面比对显示数据是否与预期值一致。因此写一个比对函数。共享一下:
'-----------------------------------------------------------------
'function:compare array with data of row in Table
'call method:
'Input parameter: obj_SelPage: SelectPage which is QTP WebList object
' obj_Table: Table which is QTP WebTable object
' pageNo: Index of row in pagelist which be compared with array
' The first index in the list is numbered 0
' rowNo: Index of row in table which be compared with array
' The first index in the table is numbered 1
' data_array: Type array
' num: compare cells which column is from 1 to num .
'For example in QTP:
' ExecuteFile "..\..\Lib\Common.vbs"
' Dim data_array(3)
' data_array(0)=datatable("userID","Action1")
' data_array(1)=datatable("Department","Action1")
' data_array(2)=datatable("Descrīption","Action1")
' data_array(3)=datatable("Account_Expires","Action1")
' call compare_list(obj_SelPage,obj_Table,1,5,data_array)
'-----------------------------------------------------------------
Public Sub compare_list(obj_SelPage, obj_Table,pageNo,rowNo,data_array,num)
Dim result
result=false
obj_SelPage.Select "#"&pageNo 'go to that page in which row is compared
colnum=obj_Table.GetROProperty("cols") 'get the number of columns in table
If num>colnum Then
'MsgBox " input parameter [num] can't greater than colnum"
Reporter.ReportEvent micFail, "check_list_result", "input parameter [num] can't greater than colnum"
Else
For c=1 to num
If trim(data_array(c-1))<>trim(obj_Table.GetCellData(rowNo, c)) then
Reporter.ReportEvent micFail, "check_list_result", "Expect result:" & data_array(c-1) & ", Display Result:" & obj_Table.GetCellData(rowNo, c)
result=false
Else
Reporter.ReportEvent micPass, "check_list_result", "Expect result:" & data_array(c-1) & ", Display Result:" & obj_Table.GetCellData(rowNo, c)
result=true
End If
Next
End If
End Sub
收藏
举报
TAG:
QTP