|
给你个函数参考,处理错误情况的,如何用自己发挥吧!
Public Function ReverseCheck( strKeys)
ReverseCheck=0
If strKeys = "" Then
reporter.ReportEvent micWarning,"要检测的值为 空","要检测的值为 空"
ReverseCheck = 0
Exit Function
End If
strSnapDir = "c:\result"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists( strSnapDir ) Then
objFSO.CreateFolder( strSnapDir )
End If
Set objFSO = Nothing
DateNow=Date
TimeNow=Time
strDate=Split(DateNow,"-")
For i=lbound(strDate) to ubound(strDate)
istrDate=istrDate&strDate(i)
Next
strTime=Split(TimeNow,":")
For i=lbound(strTime) to ubound(strTime)
istrTime=istrTime & strTime(i)
Next
imgName=istrDate & istrTime
bDlgExist = False
strTmpAltTitle = "Microsoft Internet Explorer"
If Browser("creationTime:="¤twin).Dialog("text:="&strTmpAltTitle).Exist(1) Then
strAltTitle = strTmpAltTitle
bDlgExist = True
End If
strTmpAltTitle = "Windows Internet Explorer"
If bDlgExist = false Then
If Browser("creationTime:="¤twin).Dialog("text:="&strTmpAltTitle).Exist(1) Then
strAltTitle = strTmpAltTitle
bDlgExist = True
End If
End If
If bDlgExist = True Then
Set objDesc = Description.Create()
objDesc("micclass").Value = "Static"
Set objDlgStatics = Browser("creationTime:="¤twin).Dialog("text:="&strAltTitle).ChildObjects(objDesc)
iDlgStaticCnt = objDlgStatics.Count
iDlgStaticSeq = 0
Do While iDlgStaticSeq < iDlgStaticCnt
strTextInAlert = objDlgStatics(iDlgStaticSeq).GetROProperty("text")
'If InStr(1,strTextInAlert,strKeys,vbTextCompare) >= 1Then
If cstr(strTextInAlert)=cstr(strKeys) Then
Reporter.Filter =0
Reporter.ReportEvent micPass, "反案例成功执行!", "页面存在以下错误提示"&"【"&strKeys&"】"
Reporter.Filter =1
Browser("creationTime:="¤twin).Dialog("text:="&strAltTitle).WinButton("text:=确定").Click
ReverseCheck=1
Exit Function
End If
iDlgStaticSeq=iDlgStaticSeq+1
Loop
If ReverseCheck=0 Then
' strFullName = strSnapDir & "\snap" & Environment.Value("screensnap")&".png"
strFullName = strSnapDir & "\" &imgName&".png"
Browser("creationTime:="¤twin).Dialog("text:="&strAltTitle).CaptureBitmap strFullName,True
Reporter.ReportEvent micFail, "反案例执行失败","页面实际显示【" & strTextInAlert&"】"&"与预期结果【"&strKeys&"】"&"不符。"&" 错误截图【"&imgName&".png"&"】保存位置:"&strFullName
Browser("creationTime:="¤twin).Dialog("text:="&strAltTitle).WinButton("text:=确定").Click
End If
Exit Function
End If
Set objDlgStatics = Nothing
Set objDesc = Nothing
End Function
[ 本帖最后由 jifeng 于 2008-9-12 10:50 编辑 ] |
|