Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using QTP to capture screen shot
#1
Solved: 11 Years, 4 Months, 2 Weeks ago
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"
Reply
#2
Solved: 11 Years, 4 Months, 2 Weeks ago
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
Reply
#3
Solved: 11 Years, 4 Months, 2 Weeks ago
reporter.ReportEvent throws error, it doesnt support 4 properties in qtp 9.2, dont know about other versions
Reply
#4
Solved: 11 Years, 4 Months, 2 Weeks ago
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
Reply
#5
Solved: 11 Years, 4 Months, 2 Weeks ago
Works well with QTP10.0.
Reply
#6
Solved: 11 Years, 4 Months, 2 Weeks ago
Should work fine with 9.2 with the below statement?

Reporter.Reportevent micPass,"Screenshot Capture","Screenhot Captured."&strFileName&" Is the file name"
Basanth
Give a fish to a man and you feed him for a day..Teach a man how to fish and you feed him for life.
Reply
#7
Solved: 11 Years, 4 Months, 2 Weeks ago
It is possible to paste an image to a Word document?

Thanks and regards.

Pablo.
Reply
#8
Solved: 11 Years, 4 Months, 2 Weeks ago
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."
Reply
#9
Solved: 11 Years, 4 Months, 2 Weeks ago
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
Reply
#10
Solved: 11 Years, 4 Months, 2 Weeks ago
did you add function script in library file and add it to the test you are running
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Capture screen shot for unexpected Errors. uma87 10 18,797 11-08-2014, 12:18 AM
Last Post: supputuri
  How to capture text from a tooltip using QTP sasmitakumari 2 15,042 04-03-2014, 05:59 PM
Last Post: Ankur
  qtp 11, Unable to prove the disappearance ofdynamic objects displayed on same screen. priyaang 1 2,478 03-24-2014, 12:53 AM
Last Post: supputuri
  capture screenshot using html code and view in QTP Test results Bhuvan 3 7,273 07-19-2013, 02:38 PM
Last Post: Bhuvan
  How to get uppermost java object displayed on screen using QTP shirkaan_2010 1 4,985 07-29-2011, 01:41 PM
Last Post: rajpes

Forum Jump:


Users browsing this thread: 1 Guest(s)