自己重新实现QTP封装的一些常用的方法


Function Check_ComboBox_ItemValue(objVbComboBox,strItemValue,intItemValueLength)
   Dim i
   Dim Cnt
   Cnt = objVbComboBox.GetItemsCount
   For i = 0 to Cnt -1 
           If  Trim(Left(objVbComboBox.getItem(i),intItemValueLength))= strItemValue Then
                   Reporter.ReportEvent micPass,"检查ComboBox下拉项目","下拉项目包含“" & strItemValue & "”,测试通过"
                   Exit Function
           End If
   Next
   Reporter.ReportEvent micFail,"检查ComboBox下拉项目","下拉项目不包含“" & strItemValue & "”,测试失败"
End Function 

Function Check_Objects_ItemValue(obj,arrItemValue,arrItemValueLength)
   Dim i 
   Dim Cnt
   Cnt = UBound(arrItemValue)
   strReport = obj.ToString()&"包含下列项:"
   For i = 0 to Cnt 
           If Trim(Left(obj.getItem(i),arrItemValueLength(i))) = arrItemValue(i) Then
                   strReport = strReport & vbNewLine & arrItemValue(i) 
                   Else 
                                Reporter.ReportEvent micFail,"检查控件包含项符合性","包含项不完全符合,"&arrItemValue(i)&"为第一个不符合项"
                                Exit Function
           End If
   Next
   Reporter.ReportEvent micPass,"检查控件包含项符合性",strReport
End Function

Function Check_Objects_Text(obj,strText)
   Dim i
   Dim Cnt
        txtArray = Split(obj.GetVisibleText(),vbCrLf,-1,1)
    Cnt = UBound(txtArray)  '取数组上限
        For i = 0 to Cnt
                If   Trim(txtArray(i)) = Trim(strText) Then
                        Reporter.ReportEvent micPass,"检查字符串是否一致","界面中包含字符串:"&strText
                        Exit Function           
                End If
        Next
                        Reporter.ReportEvent micFail,"检查字符串是否一致","界面中不包含字符串:"&strText
End Function 

Function Check_Object_SelectedText(obj,strText,intTextLength)
     Dim i
   Dim Cnt
        txtArray = Split(obj.GetVisibleText(),vbCrLf,-1,1)
    Cnt = UBound(txtArray)  '取数组上限
        For i = 0 to Cnt
                If   Left(Trim(txtArray(i)),intRequiredLength) = Left(Trim(strText),intRequiredLength) Then
                        Reporter.ReportEvent micPass,"检查字符串是否一致","界面中包含字符串:"&strText
                        Check_Object_SelectedText = True
                        Exit Function           
                End If
        Next
                        Reporter.ReportEvent micFail,"检查字符串是否一致","界面中不包含字符串:"&strText
                        Check_Object_SelectedText = False
End Function

Function Check_List_Selection(objVbList,Exist,strSltValue,intSltLength)
   Dim i
   Dim Cnt
   If Exist  Then
                   sltArray = Split(objVbList.GetRoProperty("Selection"),vblf,-1,1)
                    Cnt = UBound(sltArray)  '取数组上限
                For i = 0 to Cnt  
                        If Trim(Left(sltArray(i),intSltLength) = strSltValue) Then
                                        Reporter.ReportEvent micPass,"检查list选中项","选中项包含“" & strSltValue & "”,测试通过"
                                        Exit Function
                        End If
                Next
   Reporter.ReportEvent micFail,"检查list选中项","选中项不包含“" & strSltValue & "”,测试失败"
   End If
   If Not Exist Then
        If objVbList.GetRoProperty("Selection") = "" Then
                        Reporter.ReportEvent micPass,"检查list选中项","不包含任何选中项,测试通过"
                        Exit Function 
                Else
                        Reporter.ReportEvent micFail,"检查list选中项","包含某些选中项,测试失败"
        End If
        End If
End Function


你可能感兴趣的:(互联网,函数,box,combo,自动化测试,qtp)