51Testing软件测试论坛

标题: 如何让QTP自动关闭MsgBox [打印本页]

作者: madwolfer    时间: 2007-11-1 16:26
标题: 如何让QTP自动关闭MsgBox
Dim i
   Dim MyMessage
   
        For i=0 to 5
                If  (i=2) or (i=4)Then
               
rem 这是用来试验循环的一段代码
SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").WinEdit("Agent Name:").Set "admin"
Dialog("Login").WinEdit("Password:").Type "MERCURY"
Dialog("Login").WinEdit("Password:").SetSecure "472927f85bc31f6df9366529bfed91115c9dceb9"
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "4"
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;Open Order..."
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set "2"
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinMenu("Menu").Select "File;New Order"
Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"

else
         MyMessage=MsgBox("Hello Morgan.D,",65,"MsgBox Example")rem 我想让QTP自动把这个自己设置的对话框给关闭掉,请问用何种方式能成功?
         

End If rem 退出If...then 判断
next
作者: pxwcypx    时间: 2007-11-1 17:37
我也想知道如何用程序来关闭自己定义的msgbox。
作者: 木卫十二    时间: 2007-11-1 18:15
标题: 给你个代码参考
Dim res, WSH
Set WSH = CreateObject("WScript.Shell")
res = WSH.Popup("Closed after 2 seconds.", 2)  '代替msgbox "Closed after 2 seconds"
Set WSH = Nothing

不是用msgbox了
作者: xiaoyaoke    时间: 2007-11-1 18:28
标题: 精彩~~~~
呵呵,记得以前见到过同样的问题
找了半天没找到
呵呵,学了一招~~~~
作者: pxwcypx    时间: 2007-11-2 10:45
是啊我也因为这个头疼,学了挺好使的
作者: cdq1010    时间: 2007-11-2 10:58
原帖由 木卫十二 于 2007-11-1 10:15 发表
Dim res, WSH
Set WSH = CreateObject("WScript.Shell")
res = WSH.Popup("Closed after 2 seconds.", 2)  '代替msgbox "Closed after 2 seconds"
Set WSH = Nothing

不是用msgbox了



好用!
作者: loho1968    时间: 2007-11-2 13:39
QTP自己设置的MSGBOX也是一个对象
Set Msg=Description.create()
msg("text").value="MsgBox Example"
dialog(msg).close
作者: jifeng    时间: 2007-11-2 15:07
好东西
作者: zhumingwei    时间: 2007-11-5 13:10
用print不行吗?不用msgbox
作者: madwolfer    时间: 2007-11-6 13:54
原帖由 木卫十二 于 2007-11-1 18:15 发表
Dim res, WSH
Set WSH = CreateObject("WScript.Shell")
res = WSH.Popup("Closed after 2 seconds.", 2)  '代替msgbox "Closed after 2 seconds"
Set WSH = Nothing

不是用msgbox了

很好。我试验了一下,基本上可以说成功了。但是还有一个问题就是,如果你这段代码没有跟上一个Msgbox的话,在运行时会报错误。
我在下面这段代码前加了这段代码,就没有出错。
Dim i
Dim res,WSH
Set WSH=Createobject("WScript.Shell")
Set Msg=Description.create()
For i=1 to 4
   If (i=2) or (i=4) Then
        MyMessage=MsgBox("Hello Morgan.D,",vbOK) 就是这段代码,添加后,就不会报错了。如果不添加,则要象下列抓拍图一样报错
        res = WSH.Popup("Closed after 2 seconds.", 2)  '代替msgbox "Closed after 2 seconds"
        Set WSH = Nothing
   else
       SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
        Dialog("Login").WinEdit("Agent Name:").Set "admin"
        Dialog("Login").WinEdit("Agent Name:").Type  micTab
        Dialog("Login").WinEdit("Password:").Type "MERCURY"
        Dialog("Login").WinEdit("Password:").SetSecure "472ff7785a1452302b5089fbd42d83c7c005d116"
        Dialog("Login").WinButton("OK").Click
        Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
       '**********************************************
        MyMessage=MsgBox("Hello Morgan.D,",65,"MsgBox Example")
        msg("text").value="MsgBox Example"
        dialog(msg).close
        '*******************************************
        End If
Next

[ 本帖最后由 madwolfer 于 2007-11-6 14:06 编辑 ]
作者: madwolfer    时间: 2007-11-6 14:04
原帖由 loho1968 于 2007-11-2 13:39 发表
QTP自己设置的MSGBOX也是一个对象
Set Msg=Description.create()
msg("text").value="MsgBox Example"
dialog(msg).close
Dim i
Dim res,WSH
Set WSH=Createobject("WScript.Shell")
Set Msg=Description.create()
For i=1 to 4
   If (i=2) or (i=4) Then
        MyMessage=MsgBox("Hello Morgan.D,",vbOK)
         res = WSH.Popup("Closed after 2 seconds.", 2)  '代替msgbox "Closed after 2 seconds"
        Set WSH = Nothing
   else
       SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\","open"
        Dialog("Login").WinEdit("Agent Name:").Set "admin"
        Dialog("Login").WinEdit("Agent Name:").Type  micTab
        Dialog("Login").WinEdit("Password:").Type "MERCURY"
        Dialog("Login").WinEdit("Password:").SetSecure "472ff7785a1452302b5089fbd42d83c7c005d116"
        Dialog("Login").WinButton("OK").Click
        Window("Flight Reservation").WinMenu("Menu").Select "File;Exit"
       '**********************************************
        MyMessage=MsgBox("Hello Morgan.D,",65,"MsgBox Example")
        msg("text").value="MsgBox Example"这段代码在试验时,报错了,具体如抓拍图所示。不明白错误到底错在哪里?还有一个就是msg()里面添加的text这个text代表那个text,是具体指msgbox里面titile的内容,还是就是一个随便定义的一个参数而已?        dialog(msg).close        '*******************************************
        End If
Next

[ 本帖最后由 madwolfer 于 2007-11-6 14:07 编辑 ]
作者: hxf    时间: 2007-11-21 09:56
好东西,又学了两招。谢谢了。
作者: lelebachelor    时间: 2007-11-21 16:33
这错的方法。。呵呵。。
作者: ppent    时间: 2007-11-22 10:29
标题: 回复 10# 的帖子
那是你在i=2时已经执行了Set WSH = Nothing,因此在i=4时就出错了
将Set WSH = Nothing移到循环外面就可以了
作者: alex1919    时间: 2007-11-22 20:22
顶!
作者: xiasan2004    时间: 2007-11-23 10:19
有用啊
作者: lovealina    时间: 2007-11-23 18:42
有用
作者: tiangou99073    时间: 2008-1-24 17:17
还是没解决关闭Msgbox
作者: three116    时间: 2008-1-24 18:57
标题: 给你个简单的函数
'***************************************************
'msgbox information within time
'***************************************************
Public Function MsgBoxTimeout (Text, Title, TimeOut)
       Set WshShell = CreateObject("WScript.Shell")
       WshShell.Popup Text, TimeOut, Title
End Function

[ 本帖最后由 three116 于 2008-1-24 18:58 编辑 ]
作者: anTidd    时间: 2008-1-25 11:12
不就是帮助文档中的东西嘛.........
作者: three116    时间: 2008-1-25 11:30
标题: 回复 20# 的帖子
你知道还不帮助人家?!
作者: sunqiang1024    时间: 2008-1-25 16:57
原帖由 木卫十二 于 2007-11-1 18:15 发表
Dim res, WSH
Set WSH = CreateObject("WScript.Shell")
res = WSH.Popup("Closed after 2 seconds.", 2)  '代替msgbox "Closed after 2 seconds"
Set WSH = Nothing

不是用msgbox了


刚试了,不错的代码
作者: zimgxt    时间: 2008-9-8 11:39
刚用了,不错的代码,谢谢分享!!!!!!感激……
作者: 47385024    时间: 2008-9-9 16:16
恢复场景不就可以了么?哪那么麻烦???
作者: kelly33    时间: 2009-4-12 15:27
标题: 回复 7# 的帖子
QTP自己设置的MSGBOX也是一个对象
Set Msg=Description.create()
msg("text").value="MsgBox Example"
dialog(msg).close


使用这个,好像根本没办法关闭Msgbox吧。如我的语句如下:
Dim myMsg, tt
Set myMsg = Description.Create()
myMsg("text").value="test title"
tt=Msgbox("test title",vbok,"test title")
Dialog(myMsg).close
作者: ls_721521    时间: 2009-4-13 14:14
原帖由 loho1968 于 2007-11-2 13:39 发表
QTP自己设置的MSGBOX也是一个对象
Set Msg=Description.create()
msg("text").value="MsgBox Example"
dialog(msg).close



msgbox 是qtp弹出的窗口,qtp执行到它时就中断了。。。。
作者: yxd2006    时间: 2009-4-16 16:11
还是看不懂,有谁人说得更清楚点吗?
在此先谢了
作者: kasimxiao    时间: 2009-4-16 18:43
直接用print 好了嘛
作者: sincor    时间: 2010-7-20 14:03
set s=createobject("wscript.shell")
t1 = Timer
for i=1 to 10     '将其改成 1 to 1就只循环一次
s.popup "现在正在显示第"&(i)&"条信息!",1,"提示信息",4096+48
Next
t2 = Timer
MsgBox t2-t1

直接稍作修改就可以利用




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2