Code:
Function xmlcomp()
actualfolder = "C:\ERSTest\QTP\QTP_TASK\Post\"
expectedfolder = "C:\ERSTest\QTP\QTP_TASK\Pre\"
resultfolder = "C:\ERSTest\QTP\QTP_TASK\Result\"
Dim fso, f, fc, f1
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(expectedfolder)
Set fc = f.Files
For Each f1 in fc
expectedfile = expectedfolder + f1.name
actualfile = actualfolder + f1.Name
Set oXML1 = CreateObject("Msxml2.DOMDocument")
oXML1.load(expectedfile)
Set oXML2 = CreateObject("Msxml2.DOMDocument")
oXML2.load(actualfile)
Set XMLElements1= oXML1.DocumentElement.ChildNodes
Set XMLElements2= oXML2.DocumentElement.ChildNodes
If XMLElements1.length=XMLElements2.length Then
reporter.ReportEvent micPass, "Child Nodes - Equal", "Pass"
For i = 0 to XMLElements1.length-1
If XMLElements1.item(i).Text <> XMLElements2.item(i).Text Then
reporter.ReportEvent micFail, " Elements are not same- XML files are not equal", "Fail"
oXML2.save("C:\ERSTest\QTP\QTP_TASK\Result\errorfile.txt")
errorfile = "C:\ERSTest\QTP\QTP_TASK\Result\errorfile.txt"
err_update "********************************************************************", errorfile
err_update "updates start here", errorfile
err_update "********************************************************************", errorfile
Exit for
end if
Next
reporter.ReportEvent micPass, "Elements same- XML files are equal", "Pass"
else
reporter.ReportEvent micFail, "Child Nodes - Not Equal- XML files are not equal", "Fail"
End If
Next
End Function
----------------------------------------------------------------------------
Public Function err_update(errstring, errorfile)
dim fileSource, MyFile
Set fileSource = CreateObject("Scripting.FileSystemObject")
Set MyFile = fileSource.OpenTextFile(errorfile, 8, True)
MyFile.WriteLine Date & " " & Time & " : " &errstring
MyFile.Close
End Function
-----------------------------------------