Sunday, March 17, 2013

How to compare two images using QTP

We know by using Bitmap checkpoint, we can compare two images.

But is there a other way we can compare?

Yes, we can use "IsEqualBin" method from Mercury.FileCompare

sImgPath1="C:\Users\user\Downloads\SAI 01461_exposure.JPG"
'sImgPath2="C:\Users\user\Downloads\SAI 01462_exposure.JPG"
sImgPath2="C:\Users\user\Downloads\SAI 0175_exposure.JPG"
Set obj=createobject("Mercury.FileCompare")
retVal=obj.IsEqualBin(sImgPath1,sImgPath2,1,1)
print retVal
Set obj=nothing

The retVal=1 if both the images are same
else retVal=0

Monday, March 4, 2013

How to add an image at the end of the Word document

Here i divided the task into 2 steps.
1. Capture the desktop image/application.
2. Insert the captured image at the end of the word document.

sImageFilePath="D:\TempImage.png"
sWordFilePath="D:\Programming Samples\QTP\SampWord.docx"

CapturePrintScreen sImageFilePath
AddImageToWord sWordFilePath,sImageFilePath

Sub CapturePrintScreen(sFilePath)
   Desktop.CaptureBitmap sFilePath,true
End Sub

Sub AddImageToWord(sWrdFilePath,sImgFilePath)
   Const END_OF_STORY = 6
    Const MOVE_SELECTION = 0
   Set oWord=createobject("Word.Application")
    oWord.Visible=true

    set oDoc=oWord.Documents.Open(sWrdFilePath)

    Set oSelection=oWord.Selection
    oSelection.EndKey END_OF_STORY,MOVE_SELECTION

    oSelection.InlineShapes.AddPicture(sImgFilePath)

    oDoc.Save

    oWord.Application.Quit
   
    Set oWord=nothing
End Sub