QTP添加检查点并将结果写入txt文档

上一篇 / 下一篇  2013-05-08 13:48:56 / 个人分类:QTP

为了更好的实现自动化,将添加的检查点的结果计入到txt文档中。代码如下:
Browser("XX系统").Page("XX系统").Frame("main").WebElement("WebTable_2").Click
Dim a, FSO, txtPath
Const ForReading=1,ForAppending=8
 ' ForReading:打开一个只读文件,不能对此文件进行写操作
 'ForAppending:打开一个文件并写到文件的尾部
a=Browser("XX系统").Page("XX系统").Frame("main").Check(CheckPoint("main_2"))
If a="True" Then
Set FSO=CreateObject("Scripting.FileSystemObject")'创建一个文本对象
 txtPath = "D:\log.txt"
 FSO.OpenTextFile txtPath,8,true             'true表示如果当前目录下不存在1.txt文件则创建一个。
 Call QTP_Writetxt( txtPath ,"检查通过")
End If


'写入TXT的方法
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

在实现代码的过程中,我本来是想将写入文本的条件写成a=True,未考虑到a的值是一个字符串,而vb中true是布尔型。

TAG: QTP qtp 写入文本

 

评分:0

我来说两句

Open Toolbar