Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Compare two XML files, when one file is Uploaded File and the Other is Exporte
#1
Not Solved
Hi Ankur,
This is my first Thread i am posting in this blog.
We are using QTP 9.5 Version in our Company with Microsoft Windows Server 2003.I am working with automation of Portal testing.
Now i have a problem and the problem is When an xml file is uploaded in the portal after traversing through some tabs in the portal i will export the file from the portal, i need to compare with the uploaded values and the Exported values from the portal.Since i am a beginner and because as i dont have much knowing of programming i am not able to find a code for this. Can u please help me on this?

Thanks
Ramakrishna
Reply
#2
Not Solved
Hi,

Code:
Set Dc1 = CreateObject(”Msxml2.DOMDocument”)
Dc1.load(”filepath”)’file 1
Set Dc2 = CreateObject(”Msxml2.DOMDocument”)
Dc2.load(”filepath”)’file 2
Set List1= Dc1.DocumentElement.ChildNodes
Set List2= Dc2.DocumentElement.ChildNodes
If List1.length=List2.length Then’
  msgbox “Put your required one"

   For i = 0 to List1.length-1

       If List1.item(i).Text=List2.item(i).Text Then
          msgbox “Both are same"
      Else
         msgbox “Not same"
     End If
  Next
End If
Reply
#3
Not Solved

Please find the attached files and use these as xml files


Attached Files
.txt   111.txt (Size: 176 bytes / Downloads: 86)
.txt   222.txt (Size: 174 bytes / Downloads: 82)
Reply
#4
Not Solved
Hi Venkat,
Thanks for Replying. I used the same Quote for xml comparision, but in our portal there are some mandatory fields and automatically it creates XML tags when a file is exported.Now if a file is uploaded with invalid data for the field which is mandatory and if exported ,a tag is being generated with out a value .Now if i add a check point for xml comparision it must show the difference in the values.
If there is one difference between the uploaded and Exptoreted file, it is showing the difference. But it is not working fine when there are multiple differences present.

Code used in test case:---------
Code:
Dim description, filepath
Set xmlDoc1 = CreateObject("Msxml2.DOMDocument")
xmlDoc1.load("C:\Documents and Settings\Ramakrishna\QTP\Qtp Tests\EzLynx Portal\Test Data\Upload\Auto.xml")
Set xmlDoc2 = CreateObject("Msxml2.DOMDocument")
xmlDoc2.load("C:\Documents and Settings\Ramakrishna\QTP\Qtp Tests\EzLynx Portal\Test Data\ExportFile\App1.xml")
Set ElemList1= xmlDoc1.DocumentElement.ChildNodes
Set ElemList2= xmlDoc2.DocumentElement.ChildNodes
If ElemList1.length=ElemList2.length Then
    Else
          For i = 0 to ElemList1.length-1
                 If ElemList1.item(i).Text=ElemList2.item(i).Text Then
'             msgbox
                     Reporter.ReportEvent micPass,"Checking for Child Elements","child element:"&i &" is same in both XML files"
                 Else
'             msgbox
                     Reporter.ReportEvent micFail,"Checking for Child Elements","child element:"& i &" is not same in both the XML files, In XML file 1, The valueis: "& ElemList1.item(i).Text &" and In XML file 2, The valueis:"&ElemList2.item(i).Text
'                msgbox  ElemList1.item(i).nodeName
'======Checking for the Particular child for which there is a difference======
Code:
Set ElemChildList1 = ElemList1.item(i).ChildNodes
                Set ElemChildList2 = ElemList2.item(i).ChildNodes
'                msgbox ElemChildList.length
                For J = 0 to ElemChildList1.length-1
                    If  ElemChildList1.item(J).Text=ElemChildList2.item(J).Text Then
                         Reporter.ReportEvent micPass,"Checking for Error Field","There is no Difference in the Files"
                         Else
                         Reporter.ReportEvent micFail,"Checking for Error Field","child element:"& ElemChildList1.item(J).nodeName&"is not same in both the XML files, In XML file 1, The value is:"&ElemChildList1.item(J).Text&"and In XML file 2, The value is:"&ElemChildList2.item(J).Text
                         End If
                    Next
             End If
             Next
             End If
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  File Chooser on Chrome doesn't work - UFT 15.0.1 Nenna Rosa 1 3,673 10-31-2020, 01:16 PM
Last Post: Ankur
  File Pointers Reset When Using Subroutines zunebuggy 0 874 08-19-2020, 07:45 PM
Last Post: zunebuggy
  How to export the output value of a webedit object to a new excel file. mounika6677 1 1,540 04-14-2019, 05:18 PM
Last Post: mounika6677
  Invalid file error importing xls file Makhado 0 1,430 10-04-2018, 04:33 PM
Last Post: Makhado
  Access not saved excel file randhirsinghskhn 0 1,044 09-04-2018, 07:26 AM
Last Post: randhirsinghskhn

Forum Jump:


Users browsing this thread: 1 Guest(s)