QTP - Files - Files Comparison
'************************************************************************
' GAReddy @ OneTestingCenter @ QTP @ Files Comparison
'************************************************************************
FilePath="D:\TestData\"
MyFile1="OnlineScriptLog.txt"
MyFile2="OnlineScriptLog1.txt"
ResultFile="D:\TestData\ResultFile.txt"
Call CompareFiles(FilePath, MyFile1, MyFile2)
Public Function CompareFiles(FilePath, MyFile1, MyFile2)
Const ForReading = 1
Const ForWriting = 2
Const BinaryCompare = 0
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set File1 = oFSO.OpenTextFile(FilePath & MyFile1, ForReading)
Set File2 = oFSO.OpenTextFile(FilePath & MyFile2, ForReading)
Set DiffFile=oFSO.CreateTextFile(ResultFile)
' *************************************************
' ****** To Count the number of lines in File1 ***********
'*************************************************
i=0
While
File1.AtEndOfStream <> True
Line1
= File1.ReadLine
i=i+1
Wend
' *************************************************
' ****** To Count the number of lines in File2 ***********
'*************************************************
j=0
While
File2.AtEndOfStream <> True
ln2
= File2.ReadLine
j=j+1
Wend
' *************************************************
' To Check if number of
lines in File1 and File 2 are equal
'*************************************************
If
i<>j Then
Reporter.ReportEvent 1, "Line Count
", "Line Count is not equal."
else
Reporter.ReportEvent 0, "Line Count
", "Line Count is equal."
End
If
File1.Close
File2.Close
' *************************************************
' To Read text from both files to compare
'*************************************************
Set File1 =
oFSO.OpenTextFile(FilePath&MyFile1, ForReading)
Set File2 =
oFSO.OpenTextFile(FilePath&MyFile2, ForReading)
Do While
((File1.AtEndOfStream <> True) AND (File2.AtEndOfStream <> True))
' Do While
((File1.AtEndOfStream <> True))
File1Line=File1.Line
File2Line=File2.Line
File1ReadLine
= File1.ReadLine
File2ReadLine
= File2.ReadLine
Comp =
StrComp( CStr(File1ReadLine),CStr( File2ReadLine), BinaryCompare)
'
*************************************************
' To wrtie
the comparison results on DiffFile
'*************************************************
If (Comp
<> 0) then
DiffFile.WriteLine "Contents are different"
&vbtab& File1Line &vbtab&
CStr(File1ReadLine) &"***"& File2Line
&vbtab& CStr(File2ReadLine)
Else
DiffFile.WriteLine "Contents are same" &vbtab
& File1Line &vbtab& CStr(File1ReadLine)
End if
Loop
File1.Close
File2.Close
DiffFile.Close
End Function
'************************************************************************
0 comments:
Post a Comment