Verifying binary file contents (FileCompare)

UFT offers a file-comparison utility that can be used as a COM object; exactly like the DeviceReplay, as we have seen earlier in this chapter. This utility is extremely useful to compare pictures and other files storing binary data, by means of calling its IsEqualBin method, the syntax being as follows:

obj.IsEqualBin FilePathname1, FilePathname2, plErrorCode As tagCompError, [pFlags As Long]

Where obj is an instance of Mercury.FileCompare, and plErrorCode with value 0 (FC_NO_ERROR) indicates an in file compare class showing no error, and pFlags is an optional argument, which, with value 1 (FC_DIFF_SIZE), indicates an in file compare class showing difference of size.

Getting ready

From the File menu, navigate to New | Test, or use the Ctrl + N shortcut.

How to do it...

Write the following code in Action of your test:

Dim FileComparisonUtil

Set FileComparisonUtil = CreateObject("Mercury.FileCompare")

'Compare two binary files (e.g., pictures)
Print FileComparisonUtil.IsEqualBin(ExpectedFile, ActualFile, 0, 1)

How it works...

We simply pass to the function the paths of the files to be compared, and the utility does the work for us, returning True if they are equal and False otherwise.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset