未来已来
老婆测试工具培训记 -- QTP Scripting - 实践10
上一篇 /
下一篇 2008-08-05 18:09:05
/ 个人分类:自动化测试
Write a program to comparing text files?
Sub Main
fileName1 = "x:\text1.txt"
fileName2 = "x:\text2.txt"
If CompareFiles(fileName1, fileName2) Then
Msgbox "The files are equal"
Else
MsgBox "The files are different"
End If
End Sub
Function CompareFiles(fileName1, fileName2)
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'Creates the FileSystemObject object
Set fso = CreateObject("scrīpting.FileSystemObject")
'Reads the first text file
Set file1 = fso.OpenTextFile(fileName1, ForReading)
fileText1 = file1.ReadAll
file1.Close
'Reads the second text file
Set file2 = fso.OpenTextFile(fileName2, ForReading)
fileText2 = file2.ReadAll
file2.Close
'Creates the regular expression object
Set regEx = New RegExp
'Specifies the pattern for the date/time mask
'MM/DD/YYYY HH:MM:SSLL (for example: 4/25/2006 10:51:35AM)
regEx.Pattern = "\d{1,2}.\d{1,2}.\d{2,4}\s\d{1,2}:\d{2}:\d{2}\w{2}"
regEx.IgnoreCase = True
regEx.Global = True
'Replaces the text matching the specified date/time format with <ignore>
newText1 = regEx.Replace(fileText1, "<ignore>")
newText2 = regEx.Replace(fileText2, "<ignore>")
'Compares the text
If newText1 = newText2 Then
CompareFiles = True
Else
CompareFiles = False
End If
End Function
相关阅读:
- 老婆测试工具培训记 - QTP Scripting - 实践9 (pcl2004_27, 2008-8-01)
- 关于自动化测试框架的探讨 (caption, 2008-8-01)
- web自动化初步探索 (sihanjishu, 2008-8-01)
- Reflector .net程序反编译工具的一些插件 (sihanjishu, 2008-8-01)
- 开放性敏捷自动化测试架构介绍(5) (benwu, 2008-8-02)
- 一些需要继续研究的小疑问 (sihanjishu, 2008-8-03)
- 修炼成QTP高手的十个步骤【转载】 (岁月童话, 2008-8-04)
- qtp 8.2 9.2 输出Html格式报告 (pcl2004_27, 2008-8-04)
- 一个自动化测试的实例 (caption, 2008-8-05)
- 51Testing丛书连载:(十三) QTP自动化测试实践 (51testing, 2008-8-05)
收藏
举报
TAG:
自动化测试