madwolfer 发表于 2007-11-1 16:26:14

如何让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:25

:lol我也想知道如何用程序来关闭自己定义的msgbox。

木卫十二 发表于 2007-11-1 18:15:35

给你个代码参考

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:22

精彩~~~~

呵呵,记得以前见到过同样的问题
找了半天没找到
呵呵,学了一招~~~~

pxwcypx 发表于 2007-11-2 10:45:55

是啊我也因为这个头疼,学了挺好使的:victory:

cdq1010 发表于 2007-11-2 10:58:27

原帖由 木卫十二 于 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了


好用!

loho1968 发表于 2007-11-2 13:39:41

QTP自己设置的MSGBOX也是一个对象
Set Msg=Description.create()
msg("text").value="MsgBox Example"
dialog(msg).close

jifeng 发表于 2007-11-2 15:07:23

好东西

zhumingwei 发表于 2007-11-5 13:10:53

用print不行吗?不用msgbox

madwolfer 发表于 2007-11-6 13:54:23

原帖由 木卫十二 于 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 编辑 ]

madwolfer 发表于 2007-11-6 14:04:25

原帖由 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 编辑 ]

hxf 发表于 2007-11-21 09:56:45

好东西,又学了两招。谢谢了。

lelebachelor 发表于 2007-11-21 16:33:51

这错的方法。。呵呵。。

ppent 发表于 2007-11-22 10:29:59

回复 10# 的帖子

那是你在i=2时已经执行了Set WSH = Nothing,因此在i=4时就出错了
将Set WSH = Nothing移到循环外面就可以了

alex1919 发表于 2007-11-22 20:22:20

顶!:lol

xiasan2004 发表于 2007-11-23 10:19:55

有用啊

lovealina 发表于 2007-11-23 18:42:09

有用:victory:

tiangou99073 发表于 2008-1-24 17:17:01

还是没解决关闭Msgbox

three116 发表于 2008-1-24 18:57:06

给你个简单的函数

'***************************************************
'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:10

不就是帮助文档中的东西嘛.........
页: [1] 2
查看完整版本: 如何让QTP自动关闭MsgBox