如何让QTP自动关闭MsgBox
Dim iDim 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 :lol我也想知道如何用程序来关闭自己定义的msgbox。
给你个代码参考
Dim res, WSHSet WSH = CreateObject("WScript.Shell")
res = WSH.Popup("Closed after 2 seconds.", 2)'代替msgbox "Closed after 2 seconds"
Set WSH = Nothing
不是用msgbox了
精彩~~~~
呵呵,记得以前见到过同样的问题找了半天没找到
呵呵,学了一招~~~~ 是啊我也因为这个头疼,学了挺好使的:victory: 原帖由 木卫十二 于 2007-11-1 10:15 发表 http://bbs.51testing.com/images/common/back.gif
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了
好用! QTP自己设置的MSGBOX也是一个对象
Set Msg=Description.create()
msg("text").value="MsgBox Example"
dialog(msg).close 好东西 用print不行吗?不用msgbox 原帖由 木卫十二 于 2007-11-1 18:15 发表 http://bbs.51testing.com/images/common/back.gif
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:").TypemicTab
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 编辑 ] 原帖由 loho1968 于 2007-11-2 13:39 发表 http://bbs.51testing.com/images/common/back.gif
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:").TypemicTab
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 编辑 ] 好东西,又学了两招。谢谢了。 这错的方法。。呵呵。。
回复 10# 的帖子
那是你在i=2时已经执行了Set WSH = Nothing,因此在i=4时就出错了将Set WSH = Nothing移到循环外面就可以了 顶!:lol 有用啊 有用:victory: 还是没解决关闭Msgbox
给你个简单的函数
'***************************************************'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 编辑 ] 不就是帮助文档中的东西嘛.........
页:
[1]
2