Capture error image and publish it on QTP result:


Capture and report error image on QTP result:
Error handling,logging and reporting are prime challenges while developing automation framework.Our automated tests will only provide a fruitful result if it gives enough information about the test confidence (or coverage) of AUT;else Record and Run automation will only be a mission to see how software uses or manipulates software.
Image Capture:Before running the code,let’s assume the disk drive is empty enough to store our captured images.
and last but not the least,make sure that the path is relative.

Here “/” and “:” sign is replaced by “-” because file name doesnt accepts these characters.

Code:

Function CaptureImageonError()

Dim moment
Dim sMyfile

moment=Now() 'displays the current date and time
sMyfile= moment&".png"
Msgbox sMyfile
sMyfile = Replace(sMyfile,"/","-") 'removing special char / & :
sMyfile = Replace(sMyfile,":","-")
sMyfile= "C:\"&sMyfile 'Path where file would be saved

Desktop.CaptureBitmap sMyfile,true
End Function

Please refer image below to view the code to report image on result viewer(last line) as content editor doesnt allows me to type this line.

You must be wondering about &”lt” and &”gt” right?.Well,it’s just a workaround to fool QTP upto 9.5 version.Only < will do without &gt.
The difference between genius and stupidity is that genius has its limits.–Albert Einstein 😉

Output:

QTP image capture

For QTP 10+ users:
Syntax:
Reporter.ReportEvent EventStatus, ReportStepName, Details [, ImageFilePath]

Advertisements

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: