未来已来

老婆测试工具培训记 -- 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


TAG: 自动化测试

 

评分:0

我来说两句

Open Toolbar