Embedded Screenshot on QTP Report
Posted by admin - Apr 7, 2008 Articles, Dani Vainstein, QTips, Reports 0 2 Views : 1226 Receive Updates For This Category
Article Tools
- Print this page
- Add Comment
- Send to Friend
- Last Updated on :
Jul 16, 2011
Almost every test object in QTP supports the method CaptureBitmap even the Desktop object.
During your test or within a recovery scenario you want to capture a screenshot of a specific object or the desktop. to later analyze the results.
But if you want to find the bmp or png file you need to search the location of the file in your file system.
this converts the CaptureBitmap method to something not-relevant and not easy to use.
The following function will display the bitmap captured inside the QTP Report.
Public Sub CaptureScreenshot( ByRef Sender, ByVal micStatus, ByVal descriptionStr )
Dim dateTimeNow, fileNameStr, divDesc, caption
Dim dicMetaDescription, qtp
dateTimeNow = DotNetFactory.CreateInstance( "System.DateTime" ).Now.ToString( "ddMMyyHHmmss" )
fileNameStr = Reporter.ReportPath & "\" & dateTimeNow & ".png"
Set qtp = CreateObject( "QuickTest.Application" )
qtp.Visible = False : Wait 0, 500
If IsObject( sender ) Then
Sender.CaptureBitmap fileNameStr, True
caption = Sender.ToString & " - Capture Bitmap"
Else
Desktop.CaptureBitmap fileNameStr, True
caption = "Desktop - Capture Bitmap"
End If
qtp.Visible = True
divDesc = "<table align='center' border='5' cellpadding='1' cellspacing='1' width='100%' title='" & fileNameStr & "' frame='hsides'>" & _
"<caption>" & caption & "</caption>" & _
"<thead><tr><th>Application Exception Description</th></tr></thead>" & _
"<tfoot><tr><td align='center'><img border='2px' src='" & fileNameStr & "' /></td></tr></tfoot>" & _
"<tbody><tr><td>" & descriptionStr & "</td></tr></tbody></table>"
Set dicMetaDescription = CreateObject( "Scripting.Dictionary" )
dicMetaDescription( "Status" ) = micStatus
dicMetaDescription( "PlainTextNodeName" ) = "ApplicationException"
dicMetaDescription( "StepHtmlInfo" ) = "<DIV align=center>" & divDesc & "</DIV>"
dicMetaDescription( "DllIconIndex" ) = 205
dicMetaDescription( "DllIconSelIndex" ) = 205
dicMetaDescription( "DllPAth" ) = EnVironment( "ProductDir" ) & "\bin\ContextManager.dll"
Call Reporter.LogEvent( "User", dicMetaDescription, Reporter.GetContext )
End Sub
The function receive 3 parameters:
Object : the object you want to take the CaptureBitmap or vbNullString ( Empty string ) if you want to capture all the desktop.
micStatus : micPass, micFail, micWarning or micInfo
titleMessage : the title of the message in the reporter.
how to use the function?
Call CaptureScreenshot( vbNullString, micInfo, “Test” )
if you want to make the function be part of your test :
RegisterUserFunc "Page", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Browser", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Frame", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Dialog", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "swfWindow", "CaptureScreenshot", "CaptureScreenshot"
Browser("B").Page("P").CaptureScreenshot micWarning, "this is a test."


