Wednesday, December 5, 2012

How to compare two XML files using QTP

There are many ways you can compare two XML Files.

Here in this i demonstrated using XMLUtil.


'***************************************************************************************************************************************************************************************
'Objective              :  Compare two XML Files
'Functionality        : The below script compares two XML Files
'                                   s_FilePath1, s_FilePath1 These two variables holds the XML Files respctively
'                                   s_DiffFilePath will holds the difference between these two XML Files
'Author                    : Udaya Anem
'Scripted on       : 4th Sept
'Updated by         :
'***************************************************************************************************************************************************************************************

Dim s_FilePath1,s_FilePath2
Dim o_XML1,o_XML2,o_XMLDiff
Dim s_DiffFilePath
Dim b_RetVal

s_FilePath1="E:\Programming Samples\QTP Samples\Cars.xml" 'This is XML File Path 1
s_FilePath2="E:\Programming Samples\QTP Samples\Cars1.xml" 'This is XML File Path 2
s_DiffFilePath= "E:\Diff.xml"

'Set o_XML1=XMLUtil.CreateXML()
'o_XML1.loadfile(s_FilePath1)
'
'Set o_XML2=XMLUtil.CreateXML()
'o_XML2.loadfile(s_FilePath2)

Set o_XML1=XMLUtil.CreateXMLFromFile(s_FilePath1)
Set o_XML2=XMLUtil.CreateXMLFromFile(s_FilePath2)

'The Compare method from XMLData compares XML Files
b_RetVal=o_XML1.Compare(o_XML2,o_XMLDiff)

If b_RetVal=1 Then
    reporter.ReportEvent micPass,"XML Comparison","XML Comparison is Successful"
else
    reporter.ReportEvent micFail,"XML Comparison","XML Comparison is Failed"
    s_DiffFilePath=Environment("TestDir")&"\XML Diff File.xml"
    o_XMLDiff.savefile s_DiffFilePath
End If

Set o_XML1=nothing
Set o_XML2=nothing

1 comment:

  1. hello sir, do you have a php code of comparing two xml files?

    ReplyDelete