51Testing软件测试论坛

标题: QTP 发送Email 的问题, [打印本页]

作者: wsx63    时间: 2011-5-17 10:21
标题: QTP 发送Email 的问题,
Dim objOutlook
Dim objOutlookMsg
Dim olMailItem
Dim attachment

Set objOutlook = CreateObject("Outlook.Application")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
Set mapi = objOutlook.GetNameSpace("MAPI")

attachment = Reporter.ReportPath&"\Log\LogFile.html"

objOutlookMsg.To = "sixuan.wang@163.com"
'objOutlookMsg.CC = ""
'objOutlookMsg.BCC = ""
' Body of the message
objOutlookMsg.Subject = "QTP Test Mail"       
objOutlookMsg.Body = "This is a test mail"
objOutlookMsg.Attachments.Add(Reporter.ReportPath&"\Log\LogFile.html")

'Display the email
objOutlookMsg.Display
'Send the message
objOutlookMsg.Send
'Release the objects
'objOutlook.quit
Set objOutlook = Nothing
Set mapi = Nothing
上面的代码是我用来发送邮件的,想问一下红色字体部分有什么问题吗,运行到这里就报错,operation failed,但是我如果这么写:objOutlookMsg.Attachments.Add("D:\QTP\test\newUI_exit_test\Res13\Log\LogFile.html") 就没问题,D:\QTP\test\newUI_exit_test\Res13 就是我的reportpath
作者: iQuickTest    时间: 2011-5-17 10:54
试试objOutlookMsg.Attachments.Add(cstr(Reporter.ReportPath)&"\Log\LogFile.html")
作者: wsx63    时间: 2011-5-17 11:01
回复 2# iQuickTest
试过了,不行,我之前试过Cstr(Reporter.ReportPath&"\Log\LogFile.html")也不行,郁闷
作者: arivn    时间: 2011-5-17 11:11
脚本运行是没有错的,应该是因为你每运行一次时,保存结果的文件路径更新了,就找不到你的那个log文件了
作者: wsx63    时间: 2011-5-17 11:18
回复 4# arivn
但是我用的是Reporter.reportPath, 每次运行之后就是最新的路径啊,log/logFile.html这个文件是我修改注册表之后在每个res文件夹下面都会生成的
作者: zzxxbb112    时间: 2011-5-17 12:47
你的脚本是在QTP里运行的话,如果脚本没有完全运行完毕,结果文件是不会生成的,除非这个生成文件是你自己写的。如果是根据QTP本身的结果解析过来的HTML的话是需要另起一个vbs的进程等待QTP运行完毕后才能获取
作者: wsx63    时间: 2011-5-17 12:53
回复 6# zzxxbb112
我试过了,把它放到另一个action里,等前面的action运行完了在发送这个Email,也是不行,想不出原因,是不是数据类型方面的问题啊
作者: wsx63    时间: 2011-5-17 13:07
回复 6# zzxxbb112
谢谢版主,确实是你说的问题,我刚才试过hardcode这个路径,也是报错,明白原因了,还有一个问题想问你,我重新启动个vbs能获取到Reporter.ReportPath吗
作者: zzxxbb112    时间: 2011-5-17 13:12
能,利用fso动态生成一个脚本,然后用wsh去运行它,注意脚本中需要加入同步等待qtp运行完毕。
作者: wsx63    时间: 2011-5-17 13:20
回复 9# zzxxbb112
十分感谢,我去弄弄看
作者: wsx63    时间: 2011-5-17 13:39
也谢谢楼上几位的热心帮助




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