QTP运行写入日志文件

上一篇 / 下一篇  2013-04-27 10:13:17 / 天气: 晴朗 / 心情: 郁闷 / 个人分类:测试工具


Option Explicit
'==========================================================================
' 脚本说明: 写入日志文件
'
' AUTHOR: 孙强
' DATE  : 2009-12-8
'
' COMMENT:
'
'==========================================================================
'调用写入日志文件入口
'==========================================================================
'Dim sFoldername,sComtenet
'sFoldername = "D:\temp\"
'sComtenet = "测试脚本调用"
'WriteLog sFoldername,sComtenet
'==========================================================================
' 写入日志文件入口
'==========================================================================
Function WriteLog(sFoldername,sComtenet)
Dim LogTime,sFilename
LogTime = FormatDateTime(Date, 0)&" "&Time&"-------"
sComtenet = LogTime&sComtenet
sFilename = sFoldername&"\QTPlog.txt"
Dim oFSO
'创建文件系统对象
Set FSO = CreateObject ("Scripting.FileSystemObject")
Dim CheckFolderExists,CheckfileExists
'检查日志存放文件夹是否存在
CheckFolderExists = oFSO.FolderExists(sFoldername)
If CheckFolderExists = True Then
  '检查日志文件是否存在
  CheckfileExists = oFSO.FileExists(sFilename)
   If CheckfileExists = True Then
     AppendToFile sFilename,sComtenet
 Else WriteToFile sFilename,sComtenet
 End If
Else CreateFolderDemo sFoldername
  WriteToFile sFilename,sComtenet
End If
End Function
'==========================================================================
' 追加Log文件
'==========================================================================
Function AppendToFile(sFilename, sComtenet)
  Dim fso,OpenFile
  Const ForReading = 1, ForWriting = 2, ForAppending = 8
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set penFile = fso.OpenTextFile(sFilename, ForAppending, True)
    OpenFile.WriteLine(sComtenet)
    OpenFile.Close
End Function
'==========================================================================
'写入Log文件
'==========================================================================
Function WriteToFile(sFilename, sComtenet)
  Dim fso,CreateFile
  Set fso = CreateObject("Scripting.FileSystemObject")
   Set CreateFile = fso.CreateTextFile(sFilename, True)
   CreateFile.WriteLine(sComtenet)
   CreateFile.Close
End Function
'==========================================================================
'创建文件夹
'==========================================================================
Function CreateFolderDemo(sFlodername)
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.CreateFolder(sFlodername)
End Function

TAG:

 

评分:0

我来说两句

Open Toolbar