Sunday, 22 May 2011

Compare bitmap file using QTP ( using Mercury.FileCompare object )

Hi All,
We can use QTP in-build method for File compare with the help of Mercury.FileCompare.
Here I am going to describe how to use that.

Rem variable to store the location of the expected bitmap file
strstoreBMPfile = “D:\rajivkumarnandvani.bmp”
Rem variable to store the location of the actual bitmap file
strActBMPfile = “D:\rajiv\runtimebmpfile.bmp”
Rem Activate the window
Window(“Flight Reservation”).Activate
Rem Capture the actual bitmap image from the application during run-time
Window(“Flight Reservation”).Static(“Static”).CaptureBitmap strActBMPfile , True
Rem here True will overwrite the file
Rem here we write the function for compare the bitmap file using qtp inbuild method Mercury.FileCompare.
Rem Function FnCompareTwoBMPfiles
Rem Description: this function Compares two bitmap images
Rem input pathExpBMPfile path of Expected bmp file
Rem input pathActBMPfile path of Actual bmp file
Rem return value 1 if both file are same ; 0 if different

Function FnCompareTwoBMPfiles( byval pathExpBMPfile , byval pathActBMPfile)
   rem create qtp file system object
   Set objMercuryFilecompare = CreateObject(“Mercury.FileCompare”)
   rem here we use binary compare
   if objMercuryFilecompare.IsEqualBin( pathExpBMPfile , pathActBMPfile , 0,1) Then
   rem if match then return 1
    FnCompareTwoBMPfiles = 1
   rem if does not match then return 0
    FnCompareTwoBMPfiles = 0
  end if
  rem discard the object
  Set objMercuryFilecompare = nothing
End Function

Rem now we call this function
if FnCompareTwoBMPfiles(strstoreBMPfile ,strActBMPfile) = 1 then
    msgbox “ BMP file match”
    msgbox “BMP file not match”
end IF

Rem same thing we can use for other files also.


Anonymous said...

Is this function compare the BMP file with their names or this actually compare the two BMP files?

RajivKumarNandvani said...

No, It will not compare the BMP file with their names. Here it is doing binary comparison.(size, data,etc..)

Thanks for reading the blog..

Anonymous said...

I want to pass a step while comparing the Bitmap images even if sizes are different. How can I do this?

Anonymous said...

Is it possible to set RGB tolerance of the images so it does not fail when the image is captured in different browsers?

learn2automate said...

Can you plese let us know, what is the meaning of two parameters in IsEqualBin method apart from two file paths?


Post a Comment

Which one is right ?