|
本帖最后由 lyscser 于 2010-12-12 21:17 编辑
用法看注释,原理就是全部遍历,按关键字去搜寻,可能就是执行效率低一些……主要看被测系统页面框架设计的复杂度了
没怎么仔细测试,如果有问题自己改过,顺便回帖告诉我就行了,不用批斗……
- '**************************************************************************************************************************************
- '设计说明:
- ' 判断一般性的js层抛出的控制提示,根据用户选择如何做后续处理,请注意,该程序只能用于预期之外的提示处理,预期之内必须自行判断
- ' 如果不关心页面提示信息是什么,只想把提示信息抓出来,那么匹配关键字输入空值即可
- '程序输入:
- ' respath------截图文件保存路径
- ' judgeKeyWord------用于进行匹配的关键字信息,可用英文半角的逗号分隔,只有所有关键都在页面找到才视为运行通过
- ' isExitRun-------对于匹配失败的情况,选择是否彻底退出运行
- '程序输出:截图文件
- '设计人员:LIUYI027
- '设计时间:2011-12-05
- '调用举例:Call JudgeErrorForDialog("D:\","请,登录","Y")
- '**************************************************************************************************************************************
- Public Sub JudgeErrorForDialog(respath,judgeKeyWord,isExitRun)
- '判断用户传入参数
- If Trim(judgeKeyWord) = "" Then
- theKeyArray = "用户选择不做关键字匹配"&Replace(Date,"/","-")&"_"&Replace(Time,":","-")
- emptyPara = True
- End If
- theKeyArray = Split(judgeKeyWord,",")
- If Trim(Replace(isExitRun,"y","Y")) = "Y" Or isExitRun = True Then
- isExitRun = True
- ElseIf Trim(Replace(isExitRun,"n","N")) = "N" Or isExitRun = False Then
- isExitRun = False
- Else
- isExitRun = True
- Reporter.ReportEvent micWarning,"请尽量使用【Y/N】来作为您参数","由于本次输入无效,程序将自动选择在无法完全匹配的时候自动退出运行,请了解!"
- End If
- Set Wshshell = CreateObject("Wscript.Shell")
- '初始化所有打开的IE,以便确认所有的弹出窗口都已经展现在页面上
- Set BrowserObject = Description.Create()
- BrowserObject("micclass").Value = "Browser"
- Set WindowsBrowser = Desktop.ChildObjects(BrowserObject)
- brNum = WindowsBrowser.Count
- If brNum < 1 Then
- Set WindowsBrowser = Nothing
- Set BrowserObject = Nothing
- Set Wshshell = Nothing
- Exit Sub
- Else
- For bindex = 0 to brNum - 1
- WindowsBrowser(bindex).Sync
- Next
- End If
- Set WindowsBrowser = Nothing
- Set BrowserObject = Nothing
- Set DialogObject = Description.Create()
- DialogObject("micclass").Value = "Dialog"
- Set WindowsDialog = Desktop.ChildObjects(DialogObject)
- dlNum = WindowsDialog.Count
- If dlNum < 1 Then
- Set WindowsDialog = Nothing
- Set DialogObject = Nothing
- Set WindowsBrowser = Nothing
- Set BrowserObject = Nothing
- Set Wshshell = Nothing
- If emptyPara = True Then
- Reporter.ReportEvent micPass,"没有需要判断的对象","提交之后系统没有任何弹出的页面信息提示!"
- Else
- Reporter.ReportEvent micWarning,"没有需要判断的对象","提交之后系统没有任何弹出的页面信息提示!"
- End If
- Exit Sub
- End If
- For dindex = 0 to dlNum - 1
- dlTitle = WindowsDialog(dindex).GetROProperty("text")
- nameByTime = Replace(Date,"/","-")&"_"&Replace(Time,":","-")&".png"
- fileName = respath&Environment.Value("TestName")&"_"&Environment.Value("ActionName")&"_"&nameByTime
- '对于弹出的下载窗口,需要用单独的程序处理,错误判断中不做处理,直接关闭
- If INStr(dlTitle,"下载") > 0 Or INStr(dlTitle,"安装") > 0 Or INStr(dlTitle,"另存为") > 0 Or INStr(dlTitle,"保存为") > 0 Then
- WindowsDialog(dindex).Close
- End If
- 'Windows GUI直接处理掉,不在判断范围之内,如果需要使用则请自行修改(注释掉)这一段
- Set Win32Object = Description.Create()
- Win32Object("micclass").Value = "WinObject"
- Set WindowsObject = WindowsDialog(dindex).ChildObjects(Win32Object)
- woNum = WindowsObject.Count
- If woNum > 0 Then
- For windex = 0 to woNum - 1
- winMessage = WindowsObject.GetROProperty("text")
-
- If Not Trim(winMessage) = "" Then
- Reporter.ReportEvent micDone,"程序不做匹配判断的提示信息:",winMessage
- End If
- Next
- Wshshell.AppActivate(dlTitle)
- WindowsDialog(dindex).CaptureBitmap fileName
- Wshshell.AppActivate(dlTitle)
- Wshshell.SendKeys "{ENTER}"
- End If
- Set WindowsObject = Nothing
- Set Win32Object = Nothing
- Next
- '重新Count页面上的非下载窗口个数
- Set WindowsDialog = Nothing
- Set WindowsDialog = Desktop.ChildObjects(DialogObject)
- diaNum = WindowsDialog.Count
- maxCount = 0
- For dlindex = 0 to diaNum - 1
- dlTitle = WindowsDialog(dlindex).GetROProperty("text")
- nameByTime = Replace(Date,"/","-")&"_"&Replace(Time,":","-")&".png"
- fileName = respath&Environment.Value("TestName")&"_"&Environment.Value("ActionName")&"_"&nameByTime
- '对于弹出的信息提示窗口,需要获取其提示信息,以供后续选择处理方式
- Set StaticObject = Description.Create()
- StaticObject("micclass").Value = "Static"
- Set WindowsStatic = WindowsDialog(dlindex).ChildObjects(StaticObject)
- stNum = WindowsStatic.Count
- For sindex = 0 to stNum - 1
- disMessage = WindowsStatic(sindex).GetROProperty("text")
- arrindex = 0
- For arrindex = 0 To UBound(theKeyArray)
-
- If INStr(disMessage,theKeyArray(arrindex)) > 0 Then
- maxCount = maxCount + 1
- Reporter.ReportEvent micDone,"关键字匹配成功","关键字【 "&theKeyArray(arrindex)&" 】匹配成功!"
- End If
- arrindex = arrindex + 1
- Next
- Next
- Wshshell.AppActivate(dlTitle)
- WindowsDialog(dlindex).CaptureBitmap fileName
- Wshshell.AppActivate(dlTitle)
- Wshshell.SendKeys "{ENTER}"
- Next
- If maxCount < UBound(theKeyArray) + 1 Then
- Reporter.ReportEvent micFail,"函数【JudgeErrorForDialog】关键字匹配失败","您需要匹配【 "&(UBound(theKeyArray) + 1)&" 】个关键字,页面上出现了【 "&maxCount&" 】个!"
-
- If isExitRun = True Then
- Set WindowsStatic = Nothing
- Set StaticObject = Nothing
- Set WindowsDialog = Nothing
- Set DialogObject = Nothing
- Set Wshshell = Nothing
- ExitRun
- End If
- Else
- Reporter.ReportEvent micPass,"函数【JudgeErrorForDialog】关键字匹配成功","您需要匹配【 "&(UBound(theKeyArray) + 1)&" 】个关键字,页面上出现了【 "&maxCount&" 】个!"
- End If
- Set WindowsStatic = Nothing
- Set StaticObject = Nothing
- Set WindowsDialog = Nothing
- Set DialogObject = Nothing
- Set Wshshell = Nothing
- End Sub
复制代码 |
|