Can QTP do file compare?
Question ID: 105018
0
0

I’m trying to work with some files, and I don’t see any built-in way to do a file compare.

Marked as spam
Posted by (Questions: 227, Answers: 22)
Asked on May 21, 2013 3:09 pm
142 views
Answers (1)
2
Private answer

You can try using the Mercury.FileCompare undocumented object in QTP. Please look at the following code examples, and you should be able to see how you can use it. I've provided two examples. One deals with text files, and the other uses bitmaps.

'This code demonstrates how to use the Mercury.FileCompare tool

' Example of comparing two images captured during run-time against each other. In this case, we are using Notepad
Window(''Notepad'').Activate

'Capture our first bitmap image
Window(''Notepad'').WinEditor(''Edit'').CaptureBitmap ''c:notepad_before.bmp'',True

'Add some text to notepad, and capture another bitmap
Window(''Notepad'').WinEditor(''Edit'').SetCaretPos 0,0
Window(''Notepad'').WinEditor(''Edit'').Type ''This is some text''
Window(''Notepad'').WinEditor(''Edit'').CaptureBitmap ''c:notepad_after.bmp'',True

'Assign our two images to variables for comparison
a = ''C:notepad_before.bmp''
b = ''C:notepad_after.bmp''

Set objCompareUtil = CreateObject(''Mercury.FileCompare'') 'Instantiate the Mercury.FileCompare object
If objCompareUtil.IsEqualBin(a,b,0,1) Then 'Compare the two images, and report result. We should expect a failure since the images SHOULD be different

Reporter.ReportEvent micPass, ''Bitmap Check'', ''The bitmap file: ''&a & '' matched bitmap file:''& b
Else
Reporter.ReportEvent micFail, ''Bitmap Check'', ''The bitmap file: ''&a & '' did not match bitmap file:''& b
End If

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Example of comparing two text files

a = ''C:File1.txt'' 'Define text file 1
b = ''C:File2.txt'' 'Define text file 2

Set objCompareUtil = CreateObject(''Mercury.FileCompare'') ' Instantiate the Mercuy.FileCompare object
If objCompareUtil.IsEqualBin(a,b,0,1) Then 'Compare the two files and report pass or fail based on the conditional result

Reporter.ReportEvent micPass, ''Text File Check'', ''The file: ''&a & '' matched file:''& b

Else

Reporter.ReportEvent micFail, ''Text File Check'', ''The file: ''&a & '' did not match file:''& b

End If

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on May 21, 2013 3:10 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top