WORKING WITH QTP

TestEveryThinG

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

Posted by rajivkumarnandvani on June 17, 2010

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
else
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”

else
msgbox “BMP file not match”
end IF
Rem same thing we can use for other files also.

Advertisements

9 Responses to “Compare bitmap file using QTP ( using Mercury.FileCompare object )”

  1. pavan said

    really nice script its working on any file …..thanks for providing easy technic…….thanks a lot…….this script helpd for my interview,…..thanku thanku sooooo much….

  2. Thanks, All pleasure is mine 🙂

  3. lds said

    very nice script. but i have some query , is it checking bitmap wize ?
    i am compairing two pdf using Mercury.FileCompare object. please let me know how to record difference between two file into excel or text or any file

    Thanks in advance

  4. Hi thanks for reading the blog.

    Please elaborate your query in more details. what do you mean by record record difference between two file into excel or text or any file. Is posted function not solving your query??

    thanks

  5. Akshita said

    Hi,
    Nice piece of code.. I wanted to know, here if the two files matches then it will result TRUE else FALSE. Is there any other code so that we get the difference to be viewed or captured.

    If client wanted to know as where there is discripancy between both files means we cant do it with the above code.

    Can you please help in this.

  6. use examdiff tool or notepadd++ for comparing file contents

  7. Jody said

    I am interested in a similar solution, except that I am looking for only selected areas of an image. So for instance, capturing a whole webpage wouldn’t be effective because certain information always change (date, time, prices etc). So I want to capture a subarea of a page. Do you have a way to do this?

    Note: The QTP bitmap checkpoint “check only selected area” feature is not working effectively for me either (i have a defect in on that), and also I have to go through a lot to access the expected and actual images after a failure.

  8. rajivkumarnandvani said

    Hi,
    you can save the image source from the HTML of the page.

  9. Hi,

    Can anybody please provide some inputs on where can we get the complete Mercury class objects model reference.

    Thanks in anticipation.

    ~Shalabh Dixit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: