Micro Focus QTP (UFT) Forums
Using QTP to capture screen shot - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Others (https://www.learnqtp.com/forums/Forum-UFT-QTP-Others)
+--- Thread: Using QTP to capture screen shot (/Thread-Using-QTP-to-capture-screen-shot)

Pages: 1 2


Using QTP to capture screen shot - ravi.gajul - 01-31-2012

Using QTP it is possible to capture screenshots and save the file in a .bmp or png,etc file format.Here is an example I would like to share.
Code:
browser("name:=Google Maps").Page("title:=Google Maps").CaptureBitmap "c:\Googlemaps.bmp"



RE: Using QTP to capture screen shot - Ankesh - 02-01-2012

I would like to add one more point to it. png format takes less memory than bmp.

We can even associate the screenshot file to HP Run Result Viewer.

Code:
strFileName="c:\Googlemaps.png"
browser("name:=Google Maps").Page("title:=Google Maps").CaptureBitmap strFileName
Reporter.Reportevent mivPass,"Screenshot Capture","Screenhot Captured.",strFileName

The last one is the optional parameter which we can specify in the reporterevent in order to see the screenshot in the result viewer itself.

Regards,
Ankesh


RE: Using QTP to capture screen shot - rajpes - 02-03-2012

reporter.ReportEvent throws error, it doesnt support 4 properties in qtp 9.2, dont know about other versions


RE: Using QTP to capture screen shot - Ankesh - 02-03-2012

Rajpes,

I am not sure abt the versions which support this property. But it works fine with QTP 11.0.

I will check once in QTP 10.0 and update you the same.

Regards,
Ankesh


RE: Using QTP to capture screen shot - ravi.gajul - 02-03-2012

Works well with QTP10.0.


RE: Using QTP to capture screen shot - basanth27 - 02-07-2012

Should work fine with 9.2 with the below statement?

Reporter.Reportevent micPass,"Screenshot Capture","Screenhot Captured."&strFileName&" Is the file name"


RE: Using QTP to capture screen shot - phabloxar - 08-28-2012

It is possible to paste an image to a Word document?

Thanks and regards.

Pablo.


RE: Using QTP to capture screen shot - vinod123 - 08-28-2012

Capture Screenshot
1. Library file script

Code:
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

Just paste the following code above the script

Code:
RegisterUserFunc "Page", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Browser", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Frame", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "Dialog", "CaptureScreenshot", "CaptureScreenshot"
RegisterUserFunc "swfWindow", "CaptureScreenshot", "CaptureScreenshot"
use the below line for capturing screenshot

Code:
Browser("micclass:=Browser").Page("micclass:=Page").CaptureScreenshot micPass, "Page ScreenShot."



RE: Using QTP to capture screen shot - sims - 02-09-2015

Hi All, I am new [typical] to QTP and I can't get the screenshot to work. I need to capture a screenshot of each screen that my script runs through for evidence sake.

If I have my understanding correct I need to create the function via the function definition generator tool?

The below is my script. However My screenshot code is failing every time. Can anyone help?

My appreciated in advance.


Code:
'RegisterUserFunc "Browser", "CaptureBitmap", "fnCaptureBitmap1"
Browser("Santander UK").Page("Santander UK").Image("idUserMenu").Click
'login user'
Browser("Intranet Login").Page("Intranet Login").WebEdit("calias").Set "c0234599"
Browser("Intranet Login").Page("Intranet Login").WebEdit("cpassword").SetSecure "54d52cac4a591499190479343ef8adc2f850270e6a8074ed81545d5baee1"
'navigate to customer search'
Browser("Intranet Login").Page("Intranet Login").WebButton("OK").Click
Browser("Intranet Login").Page("Intranet Login").Frame("menuIzq").WebElement("Customer Database").Click

'search for customer'
Browser("Intranet Login").Page("Intranet Login").Frame("menuIzq").Link("Details Management").Click
Browser("Intranet Login").Page("Intranet Login").Frame("AreaTrabajo").WebList("select").Select "Customer Number"
Browser("Intranet Login").Page("Intranet Login").Frame("AreaTrabajo").WebEdit("WebEdit").Set "33809222"
Browser("Intranet Login").Page("Intranet Login").Frame("AreaTrabajo").Link("Search").Click

'#####################
'Capture screenshot
'#####################
Public Function ScreenshotCapture(ByRef test_object)
'Browser("Intranet Login").Page("Intranet Login").CaptureBitmap "C:\QTP\Screenshots"
End Function
RegisterUserFunc "Image", "CaptureBitmap", "ScreenshotCapture"

Browser("Intranet Login").Page("Intranet Login").Frame("AreaTrabajo_2").Link("Details").Click
Browser("Intranet Login").Page("Intranet Login").Frame("AreaTrabajo_2").WebElement("0015").Click
Browser("Intranet Login").Page("Intranet Login").Frame("AreaTrabajo_2").Link("Details").Click
Browser("Intranet Login").Page("Intranet Login").Frame("AreaTrabajo_2").Link("Address").Click
'################################
'Capture Screenshot
'################################

'Test End



RE: Using QTP to capture screen shot - vinod123 - 02-10-2015

did you add function script in library file and add it to the test you are running