我叫陈永达,欢迎来到我的51testing空间!
才开始使用,想把关于软件测试的一些资料和心得保存于此。
欢迎大家多来参观,多提宝贵意见!
【QTP】写入txt文件的操作
上一篇 /
下一篇 2012-10-21 11:17:05
/ 个人分类:QTP
在QTP中,经常会遇到需要写入外部文件的地方,比如写Log什么的,这时,可以使用下面代码进行写Txt操作。
'新建文件 Dim FSO Const ForReading=1,ForWriting=2,ForAppending=8 '参数赋值(1:只读,2:只写,3:追加) Set FSO = CreateObject("Scripting.FileSystemObject") '创建一个文本对象
Dim txtPath txtPath = "D:\log.txt" FSO.OpenTextFile txtPath,8,true 'true表示如果当前目录下不存在1.txt文件则创建一个。
Set FSO = Nothing
'写文件 Call QTP_Writetxt(txtPath,"我是追加") Call QTP_Writetxt2(txtPath,"我是改写") |
然后是两个函数:
'=========================================== '写文件函数(追加) '=========================================== Public Function QTP_Writetxt(oPath,words) Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") Set logFile = FSO.OpenTextFile(oPath, 8, true) logFile.WriteLine (CStr(words)) logFile.Close
Set logFile = Nothing Set FSO = Nothing End Function
'=========================================== '写文件函数(改写) '=========================================== Public Function QTP_Writetxt2(oPath,words) Dim FSO Set FSO = CreateObject("Scripting.FileSystemObject") Set logFile = FSO.OpenTextFile(oPath, 2, true)
logFile.WriteLine (CStr(words)) logFile.Close
Set logFile = Nothing Set FSO = Nothing End Function |
除了直接打印之外,我还会加上写html语句,然后新建文件的后缀名也改成.html,这样,保存的文件就是一个网页啦,可以写入超链接,颜色,插入图片等等一系列动作。
这样,一个打印就可以做到图文并茂啦~
下面的图是我的用法,用了下QTP报告自带的CSS,大概如下
收藏
举报
TAG:
写文件
写txt
软件测试
QTP
陈永达