Tuesday, September 4, 2012

To capture application screenshot and display it in test results

Hey folks,

A common feature that QTP testers are often asked to implement is to capture the application screenshot every time an error occurs during test run. This is definitely a good to have feature in your automation framework because -
a) When a script fails, you would have a proof that it failed due to an application issue and not due to your script, and
b) with the error screenshot, the developers usually find it easier to identify/fix the issue.

QTP provides a method called CaptureBitmap that can capture the image of either an object within the application or the entire screen/desktop and save it in any desired location. The image is saved as .png or .bmp file depending upon the file extension provided during the function call. The object is captured as it appears in the application when the method is performed. If only a part of the object is visible, then only the visible part is captured

Function fnDisplayBitmapInTestResults
URL="www.gmail.com"

 SystemUtil.Run "iexplore.exe", URL
browsernm=".*gmail.*"
Pagenm=".*gmail.*"
Set CurrObj=Browser("name:="&browsernm).Page("title:="&Pagenm)
wait(5)
currobj.CaptureBitmap "d:\Test.bmp"
Reporter.ReportEvent micDone ,"Image", "Image", "D:\Test.bmp"
End Function

call  fnDisplayBitmapInTestResults

Notes:
1. You cannot load images from Quality Center.
2. If you include large images in the run results, it may impact performance.
3. If you specify an image as a relative path, QTP will first search the Results folder for the image and then the search paths specified in the Folders pane of the Options dialog box

No comments:

Post a Comment