One of our QTP forum members, Rajesh, asked “Is it possible to capture the bitmap image of our application and place the same in to the report sheet?”. Nice question. I thought I would make it as a blog post rather than answering in forum so that it could reach a wider audience.
I did some R&D and was able to arrive at a solution. Though I got the solution for his problem but it left me with one of my questions unsolved! First I would explain how I got the solution and then would throw open my question.
The QTP result viewer is like an HTML page. You can view the source as you do it in normal HTML pages using Right Click > View Source
option. Now, In order to place a bitmap image in report sheet you need to tweak the Reporter.ReportEvent a little. After all, that’s the way we reach and customize our pass/warning/fail statements in result viewer.
Dim path_error_file 'Declare a variable which contains path of the error image' path_error_file = "C:Documents and Settings\ankurjain\Desktop\error.bmp" 'Place the image on desktop' Browser("Browser").CaptureBitmap path_error_file,True 'Use CaptureBitmap method to capture the screenshot, True will overwrite an existing error.bmp file' Reporter.ReportEvent micFail,object_snap,"&amp;<img src='" & path_error_file &"'>"
Third argument in Reporter.ReportEvent
take Details as input. I provided the path of error file, the same way we do for any webpage using img
tag. This is the whole solution.
Well, did you notice something extra? There is an &amp;
before img
which is troubling me. While trying to reach at the solution I thought this statement Reporter.ReportEvent micFail,object_snap,"<img src='" & path_error_file &"'>"
should work but it didn’t.
In HTML if you want to render < (less than sign) you can write &lt;
, similarly for > (greater than sign) you can write &gt;
hence I tried using Reporter.ReportEvent micFail,object_snap,"&lt;img src='" & path_error_file &"'&gt;"
but again with no solution. Finally I tried Reporter.ReportEvent micFail,object_snap,"&lt;<img src='" & path_error_file &"'>&gt;"
and yes it WORKED!.
Here I found something interesting, even if I removed &lt;
OR &gt;
it still worked. Or for that matter any escape sequence worked if I include it either before img tag or as a closing tag.
I am just not able to understand this and I think, I am missing out something. Can someone guide me?
Please use QTP forums for posting QTP questions.
Hi,
Can anyone tell how to capture screenshot in sap while the script is running
Function Capture_Scroll_Image
Set objShell = CreateObject(“WScript.Shell”)
Set oSnag = CreateObject(“SNAGIT.ImageCapture”)
oSnag.Input = 1
oSnag.Output = 2
‘oSnag.OutputImageFile.FileNamingMethod = 2
oSnag.OutputImageFile.FileNamingMethod = 1
‘oSnag.OutputImageFile.Directory = “C:\Documents and Settings\Desktop”‘Make sure to specify your file path where you need to save your screen capture file.
oSnag.OutputImageFile.Directory = “D:\Rajesh_Mail\Rajesh\2014\Documents\Images”
oSnag.OutputImageFile.Filename = “Name”
oSnag.EnablePreviewWindow = False
oSnag.AutoScrollOptions.AutoScrollMethod=3
oSnag.OutputImageFile.LoadImageDefaults 5
oSnag.Capture()
wait(2)
objShell.SendKeys “{ENTER}”
Do Until oSnag.IsCaptureDone
Loop
Set oSnag=Nothing
Set objShell=Nothing
End Function
Call this function where you want to capture the screen image
Hi
How should I compare two images? It can be a bitmap or jpeg file format.
Thanks
Kumar
Hi,
I want to take multiple screenshot and paste in the result html page. Actually the current bechaviour is capturing the screenshot when the script get failed, but i want to take the screenshots where are the scripts to get pass, for eg, if my scripts has 10 pass condition, then i need to take 10 screenshot. Could you please anyone let me know “How to take muliple screenshot”
Thanks for the post. Wonderful
Hi All,
I need your help .The problem which I am facing is that :
1. As the image is getting saved in local system,other users are not able to view the image attached in the result file and also once if the images are deleted from the local , again no images will be displayed in the result file.
2.I tried saving the images in the temp folder but still facing the same issue.
3.Tried attaching the images to Test sets in QC , but then the screen shots are not getting displayed in the Result file . It just comes as an attachment.
Is there any way to permanently attach the screen shots to result files in QC, so that any one can view the images, even if the images are deleted from the local machine.
Hi, I am using QTP 9.5 to run SAP scripts via QC.At the end of a test, test result is generated along with screen shots of all the steps irrespective of a step being passed or failed. What I am looking for is a way to export all of the screen prints to a word/pdf document which can be opened and viewed at without any dependency on QTP or QC. A piece of code or anything which could facilitate this would be appreciable.
Kindly mail me at: veloice007@gmail.com
Hello all,
after recording a session and running the script to verify the result am getting the below error.
The test run cannot continue due to an unrecoverable error.
Failed to run script.
Description: The specified module could not be found.
Line (1): “RunAction “Action1″, oneIteration”.
COuld you please suggest a way forward.
Thanks in Advance.
how can i identify the object which is embeded in activX table?
hi all,
This is abhinav.
I want to give a link on the result viewer on which,when i click that link it should give the screenshot that is saved on my desktop.
Is it possible????
i m giving the code…jst chk that and pls help asap
(“If var=false Then“
Reporter.ReportEvent 0,”abcd”,”
else
Reporter.ReportEvent 1, “abcd”, “abcd”
End If”)
here z is a shared drive.
hi all,
This is abhinav.
I want to give a link on the result viewer on which,when i click that link it should give the screenshot that is saved on my desktop.
Is it possible????
Thanks Alex. That was nice.
Hi all,
We are using QualityCenter 9.0 to control our QTP test execution.
The code I use to display screenshots in the test results is only a little different to Ankurs:
The key to making the screenshots visible when executing on multiple machines is to include the FULL PATH to the screenshot. I have written a function to gather the local machines hostname.
‘|| This Code uses my custom function “GetHostname()” to determine the local and full path for the screenshot.
vPath = “D:\Screenshots”
vHostname = GetHostname()
vCapture=””& vPath &”\”&Replace(Replace(Replace(FormatDateTime(Now,vbGeneralDate),” “,”_”),”/”,”-“),”:”,”.”) & “.png”
vReporterPath = Right(vCapture,Len(vCapture)-2)
vReporterPath = “\\” &vHostname&vReporterPath
‘|| Report the full path to the screenshot separately in case the image does not display for some reason.
Reporter.ReportEvent micDone, “Screenshot Path”,vReporterPath
‘ || Take Snapshot of Test Application
Browser(“title:= MSD/EDS Swatt Test Application”).Page(“title:= MSD/EDS Swatt Test Application”).CaptureBitmap vCapture,True
‘|| Check that snapshot was was successful. If not take screenshot of whole desktop.
Dim fso, f
Set fso = CreateObject(“Scripting.FileSystemObject”)
If Not(fso.FileExists(vCapture)) Then
Reporter.ReportEvent micDone,”Screenshot failed”,” – full Desktop screenshot taken”
Desktop.CaptureBitmap vCapture,True
End If
Reporter.ReportEvent micDone, “Screenshot”, “AAAimg src=” & chr(34) & vReporterPath & chr(34) & “BBB”
Please note that certain HTML tags have been disabled, so I have had to be creative…
AAA represents: & l t ; <
BBB represents: > & g t ;
(with no spaces!)
Hi to All, Can anyone let me know how to use the Screenshot when we launch the result from QC,
Actually I am running the test from QC, am using the same method to post the Screenshot to QTP result. But when the test is finished the run and if i open the result from QC, i can not see the screenshot,… so any solution for this…….
Hi,
Your analysis and solution to the problem is very good.
One thing I observed is that, the < and > characters are displayed as part of the result details. I mean there is < to the bottom left corner of the image and > to its bottom right corner.
Is this possible even when QTP is Integrated to QC?. i tried and it didn’t work well
Thanks a lot !
I’d problems when trying to include screenshots to a report in my QTP test. Exactly the same problem you described.
I managed to find an awful solution that did work by reparsing the results.xml file. It was taking a lot of time…
Go on, you website is the most complete about QTP !