Comparing two XML files via QTP (860 Views)
Reply
Occasional Visitor
Varun Jain
Posts: 1
Registered: ‎07-02-2010
Message 1 of 7 (860 Views)

Comparing two XML files via QTP

[ Edited ]

Hi,
I wanna run the following scenario in QTP:

Compare two XML files and report the mismatch(if any).

 

 

P.S. this thread has been moved from Quality Center Support and News Forum to Unified Functional Testing (formerly QTP) News and Support Forum - Hp Forum moderator

Please use plain text.
Honored Contributor
john scarpino
Posts: 1,344
Registered: ‎02-15-2008
Message 2 of 7 (860 Views)

Re: Comparing two XML files via QTP

Hi Varun,

You have two options.

#1 You could script it to open the .XML file in MS Word then within MS Word select the Tools menu, click Compare and Merge Documents.

#2 You could also try...

Public Function CompareFiles (FilePath1, FilePath2)
Dim FS, File1, File2
Set FS = CreateObject(â Scripting.FileSystemObjectâ )
If FS.GetFile(FilePath1).Size <> FS.GetFile(FilePath2).Size Then
CompareFiles = True
Exit Function
End If
Set File1 = FS.GetFile(FilePath1).OpenAsTextStream(1, 0)
Set File2 = FS.GetFile(FilePath2).OpenAsTextStream(1, 0)
CompareFiles = False
Do While File1.AtEndOfStream = False
Str1 = File1.Read(1000)
Str2 = File2.Read(1000)
CompareFiles = StrComp(Str1, Str2, 0)
If CompareFiles <> 0 Then
CompareFiles = True
Exit Do
End If
Loop
File1.Close()
File2.Close()
End Function

I hope this helps.
John Scarpino
Please use plain text.
Honored Contributor
john scarpino
Posts: 1,344
Registered: ‎02-15-2008
Message 3 of 7 (860 Views)

Re: Comparing two XML files via QTP

The code line for Set FS should read.....

Set FS = CreateObject(â Scripting.FileSystemObjectâ )
Please use plain text.
Honored Contributor
john scarpino
Posts: 1,344
Registered: ‎02-15-2008
Message 4 of 7 (860 Views)

Re: Comparing two XML files via QTP

Set FS = CreateObject(**QUOTE**Scripting.FileSystemObject**END QUOTE**)
Please use plain text.
Advisor
Pete21
Posts: 19
Registered: ‎05-13-2013
Message 5 of 7 (689 Views)

Re: Comparing two XML files via QTP

Hello,

 

I am trying the Compare method of QTP to compare two XML files

However, I want to make this method more 'clever'

 

To be more precise,

If the first XML file has the a value 2 and the second XML file has the value 2.0, then the comparison fails.

However, 2 and 2.0 is the same actual number.

 

Could you please let me know your thoughts on this?

Please use plain text.
Honored Contributor
RoniRobinson
Posts: 623
Registered: ‎07-21-2011
Message 6 of 7 (685 Views)

Re: Comparing two XML files via QTP

We used a third party tool called Beyond Compare for comparison of XML files.  Within the QTP script, we gave the WShell commands necesary to open Beyond Compare with the two file names.  We then retrieved the pass/fail on the comparison.  If failed, we screen captured the Beyond Compare screen showing the difference(s).

 

That was at a previous company and I no longer have access to the actualy code written to perform these functions.

Please use plain text.
Advisor
Pete21
Posts: 19
Registered: ‎05-13-2013
Message 7 of 7 (677 Views)

Re: Comparing two XML files via QTP

Thank you a lot for your reply,

 

I will try this for sure

However, Since I will give the scripts to our client, I cannot 'force them' to use a third party application

 

I have to find  solution into QTP

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation