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
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
&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.
If you want to keep track of further articles on UFT (QTP). I recommend you to subscribe by Email and have new UFT articles sent directly to your inbox.