|
当中有对SAFFRON框架的增加改造,有一些自己常用的方法或函数,使用时请注意有相互调用,出错不怪我……
在SAFFRON基础上不知道是否能够构造出更加强大、更便于开发和管理的框架函数库呢?
-
- '*******************************************************************************************************************************
- '设计说明:关闭所有打开的IE
- '程序输入:
- '程序输出:
- '设计人员:LIUYI027
- '设计时间:2011-01-08
- '调用举例:CloseBrowsers
- '*******************************************************************************************************************************
- Public Sub CloseAllBrowser
- Set Wshshell = CreateObject("Wscript.Shell")
- Set DialogObject = Description.Create()
- DialogObject("micclass").Value = "Dialog"
- Set Windows32Dialog = Desktop.ChildObjects(DialogObject)
- dlNum = Windows32Dialog.Count - 1
- For v = 0 to dlNum
- Windows32Dialog(v).Close
- Next
- Set Windows32Dialog = Nothing
- Set theBrowser = Browser("micclass:=Browser", "index:=0")
- While theBrowser.Exist(0)
- theBrowser.Close
- '有些系统页面可能在关闭的时候会有提示对话框出现
- waitNx = 1
- Do While waitNx < 5
- Set Windows32Dialog = Desktop.ChildObjects(DialogObject)
- dlNum = Windows32Dialog.Count - 1
- For v = 0 to dlNum
- dlText = Windows32Dialog(v).GetROProperty("regexpwndtitle")
- Wshshell.AppActivate(dlText)
- Wait(1)
- Wshshell.SendKeys "{ENTER}"
- Next
- Set Windows32Dialog = Nothing
- waitNx = waitNx + 1
- Loop
- Report Pass,"使用CloseAllOpenedBrowsers函数页面关闭成功","当前页面关闭成功!"
- Wend
- Set theBrowser = Nothing
- Set DialogObject = Nothing
- Set Wshshell = Nothing
- End Sub
- '*******************************************************************************************************************************
- '设计说明:最大化IE浏览器
- '程序输入:无
- '程序输出:无
- '设计人员:LIUYI027
- '设计时间:2011-01-08
- '调用举例:MaximizeBrowser
- '*******************************************************************************************************************************
- Sub MaximizeBrowser
- Set BrowserObject = Description.Create()
- BrowserObject("NativeClass").Value = "IEFrame"
- Set WindowsBrowser = Desktop.ChildObjects(BrowserObject)
- brNum = WindowsBrowser.Count - 1
- For i = 0 To brNum
- ieVersion = WindowsBrowser(i).GetROProperty("version")
- wndTitle = WindowsBrowser(i).GetROProperty("title")
- Set ObjectBrowser = Browser("micclass:=Browser", "index:="&i)
- If Instr(ieVersion,6) > 0 Then
- Window("regexpwndclass:=IEFrame","index:=0","text:="&wndTitle&".*").Maximize
- Else
- WindowsBrowser(i).Maximize
- End If
- Set ObjectBrowser = Nothing
- Next
- Set WindowsBrowser = Nothing
- Set BrowserObject = Nothing
- End Sub
- '*******************************************************************************************************************************
- '设计说明:初始化所有打开的Browser页面,不厌设计复杂只为稳定高效
- '程序输入:无
- '程序输出:初始化成功或者失败
- '设计人员:LIUYI027
- '设计时间:2011-01-08
- '调用举例:BrowserSync
- '*******************************************************************************************************************************
- Public Function SyncronizeBrowser()
- Set MyBrowser = Browser("micclass:=Browser", "index:=0")
- If MyBrowser.Exist(0) Then
- MyBrowser.Sync
- Do Until MyBrowser.GetROProperty("url") <> "" And MyBrowser.GetROProperty("name") <> ""
- Delay 50
- Loop
- Else
- Set MyBrowser = Nothing
- SyncronizeBrowser = False
- Report Warning ,"初始化页面失败","页面初始化失败,需要重新操作!"
- Exit Function
- End If
- Set MyBrowser = Nothing
- SyncronizeBrowser = True
- End Function
- '*******************************************************************************************************************************
- '设计说明:打开指定的地址,并且初始化页面,特别说明:对于地址栏出现一次性sessionid的网页不可用该函数
- '程序输入:url地址
- '程序输出:初始化成功或者失败
- '设计人员:LIUYI027
- '设计时间:2011-01-08
- '调用举例:print SyncronizeSepecifiedURL("www.baidu.com")
- '*******************************************************************************************************************************
- Public Function NavigateBrowser(para_myuri)
- CloseAllBrowser
- Set IEBrowser = CreateObject("InternetExplorer.Application")
- IEBrowser.Visible = True
- IEBrowser.Navigate para_myuri
- Set ObjectBrowser = Browser("micclass:=Browser", "index:=0")
- Do Until SyncronizeBrowser() = True
- Wait(1)
- Loop
- actualurl = ObjectBrowser.GetROProperty("url")
- '下面这个判断主要是为了解决初始化地址跳转问题,如果URL发生变化会导致对象属性发生变化从而导致运行错误。
- If actualurl <> para_myuri Then
- ObjectBrowser.Close
- Set IEBrowser = Nothing
- Set IEBrowser = CreateObject("InternetExplorer.Application")
- IEBrowser.Visible = True
- IEBrowser.Navigate actualurl
- If Not SyncronizeBrowser() Then
- Report Warning,"使用NavigateBrowser函数IE初始化失败","打开指定页面【"&myuri&"】在初始化的时候失败!"
- Set MyBrowser = Nothing
- Set IEBrowser = Nothing
- Exit Function
- End If
- End If
- Set ObjectBrowser = Nothing
- Set IEBrowser = Nothing
- Report Pass,"使用NavigateBrowser函数IE初始化成功","打开指定页面【"¶_myuri&"】并且初始化成功!"
- NavigateBrowser = True
- End Function
- '*******************************************************************************************************************************
- '设计说明:处理弹出对话框,主要用于弹出的可预知性能够得到控制的地方,未知弹出需引用其他函数处理
- '程序输入:选择对话框操作:是/否/确认/取消/确定等等,是否需要向结果中添加提示信息的报告
- '程序输出:结果报告
- '设计人员:LIUYI027
- '设计时间:2011-01-08
- '调用举例:HandleDialog "确认","Y"
- '*******************************************************************************************************************************
- Public Function HandleDialog(regexpName,needAlertInfo)
- If Trim(regexpName) = "" Then
- regexpName = "无需匹配的按钮!"
- End If
- Set Wshshell = CreateObject("Wscript.Shell")
- Set DialogObject = Description.Create()
- DialogObject("micclass").Value = "Dialog"
- Set WindowsDialog = Desktop.ChildObjects(DialogObject)
- dlNum = WindowsDialog.Count - 1
-
- If dlNum < 0 Then
- Set WindowsDialog = Nothing
- Set DialogObject = Nothing
- Report micDone,"没有任何弹出框","不需要进行对话框的处理!"
- Exit Function
- End If
- For inx = 0 to dlNum
- If needAlertInfo = "Y" Or needAlertInfo = True Then
- Set StaticObject = Description.Create()
- StaticObject("micclass").Value = "Static"
- Set WindowsStatic = WindowsDialog(inx).ChildObjects(StaticObject)
- stNum = WindowsStatic.Count
- disMessage = WindowsStatic(stNum - 1).GetROProperty("text")
- Report micDone,"获取网页对话框信息成功:",disMessage
- Set WindowsStatic = Nothing
- Set StaticObject = Nothing
- End If
- dialogTitle = WindowsDialog(inx).GetROProperty("text")
- Set WinButtonObject = Description.Create()
- WinButtonObject("micclass").Value = "WinButton"
- Set WindowsButton = WindowsDialog(inx).ChildObjects(WinButtonObject)
- wbNum = WindowsButton.Count - 1
- For binx = 0 to wbNum
- btName = WindowsButton(binx).GetROProperty("text")
- If Instr(btName,regexpName) > 0 Then
- WindowsButton(binx).Click
- Report Pass,"函数HandleDialog点击指定按钮成功","按照指定的按钮名称【"®expName&"】查找并点击按钮成功!"
- Exit For
- End If
- If binx = wbNum And Instr(btName,regexpName) = 0 Then
- Wshshell.AppActivate(dialogTitle)
- Wait(0)
- Wshshell.SendKeys "{ENTER}"
- Report micWarning,"函数HandleDialog点击按钮","没有匹配到指定按钮,对已经弹出的对话框直接使用默认操作!"
- End If
- Next
- Set WindowsButton = Nothing
- Set WinButtonObject = Nothing
- Next
- Set WindowsDialog = Nothing
- Set DialogObject = Nothing
- Set Wshshell = Nothing
- End Function
- '*******************************************************************************************************************************
- '设计说明:SAFFRON框架引用以及部分改造,函数分流之后的部分
- '程序输入:参见各个函数
- '程序输出:
- '设计人员:
- '设计时间:2011-01-08
- '调用举例:
- '*******************************************************************************************************************************
- Public Function GenerateDescription (classString,isModleWindow)
- classNx = IndexOf(classArray, classString)
- If classNx >= 0 Then
- '增加对模态窗口的支持
- If isModleWindow = "Y" Or isModleWindow = True Then
- descString = "Window("&Quote("nativeclass:=Internet Explorer_TridentDlgFrame")&")."
- Else
- descString = classArray(0)&"("&Quote(descArray(0))&")."
- End If
- If classNx >= 1 Then
- descString = descString + classArray(1)&"("&Quote(descArray(1))&")."
- If 2 >= classNx Then
- If hasFrameValue <> "" Then
- descString = descString + classArray(2)&"("&Quote(descArray(2))&","&Quote("name:="&hasFrameValue)&")."
- End If
- End If
- End If
- End If
- GenerateDescription = descString
- End Function
- '************************************************************************************************************************
- Public Function GenerateObjectDescription (objClassName, otherAtt)
- objNx = IndexOf(objectArray, objClassName)
- objNameString = ""
- If objNx <> -1 Then
- objNameString = objClassName&"("&Quote(objectDescArray(objNx))&","&Quote(otherAtt)&","&Quote("index:=0")&")."
- End If
- GenerateobjectDescription = objNameString
- End Function
- ……
- ……
- ……
复制代码 |
|