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

Thursday, February 7, 2013

QTP unables to identify pop up window


There are couple of scenarios where we perform some operations in a application, where a pop up window will appear like:
1. When you delete a user/emp, it will display a pop up saying "Do you want to Delete the user?"
2. You choose some pop up menu option, then a pop up window may be displayed with the selected items functionality.

For sometimes, even though you have the correct recorded script, it may throw you an error saying the object does not exist.

Ex: B("XYZ").Dialog("Delete User").WinButton("Ok").click    may throw error saying "Object not visible".

How to overcome this error?

Cause: The "visible" property of the Parent object may not enabled.

Solution: Goto Tools -> Object Identification -> Choose Environment type -> Choose the object class(in our case Browser is the parent to the Dialog box) -> Click on Add/Remove property -> select "visible" property.
After visibility property is configured, now re-record the steps.

Now QTP should be able to identify the pop up window.

Tuesday, February 5, 2013

How to get QTP Results in a HTML file

Once we ran our Regression suite, it is handy if the results are displayed in HTML File, it is easy for us to understand at the same time also easy for the management(Lead/Manager/Customer) to look at it.

They will not show any interest if you zip your QTP Result folders and send it to them.

And for many reasons it is handy if the results are displayed in HTML File, right? How can we get the results in HTML File.

But how can we view results in HTML File?

By changing one registry setting, we have get QTP results in a HTML File.

Open windows registry by entering regedit and clicking enter in Windows run.

HKLM\Software\MercuryInteractive\QuickTestProfessional\Logger\Media\Log

Double click on "Active"

Change the value from 0 to 1.

Restart QTP.

Now run your QTP Test and see results in the QTP Test folder, where you see a "Log" folder.

In this folder you will see a file called LogFile.html which is the HTML Report.

Friday, February 1, 2013

How to check the website you are testing is up and running

We can check the website up and running by just pinging the website.

You can do that in couple of ways.

Here is the simplest way to  ping a website.

Appraoch1:

strWebSiteName="www.yahoo.com"
strQuery = "SELECT * FROM Win32_PingStatus WHERE Address = '" & strWebSiteName & "'"
bFlag = False

Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set objItems = objWMIService.ExecQuery( strQuery )

For Each objItem In objItems
       If objItem.StatusCode = 0 Then
            bFlag = True
            Exit For
        Else
            bFlag = False
        End If
Next

If bFlag = true Then
    print "Website is avilable"
else
    print "Website not avilable"
End If

Set objItems = Nothing
Set objWMIService = Nothing

Appraoch2:
Set oNetwork = DotNetFactory( "Microsoft.VisualBasic.Devices.Network" ,"Microsoft.VisualBasic")
bFlag=oNetwork.ping(strWebSiteName)
If bFlag Then
  print  "Website is avilable"
Else
   print  "Website not avilable"
End If
Set oNetwork=nothing