{"id":673,"date":"2011-11-13T04:23:41","date_gmt":"2011-11-12T22:53:41","guid":{"rendered":"http:\/\/www.automationrepository.com\/?p=673"},"modified":"2011-11-13T04:24:09","modified_gmt":"2011-11-12T22:54:09","slug":"how-to-capture-application-screenshot-using-qtp","status":"publish","type":"post","link":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/","title":{"rendered":"How to capture application screenshot and display it in test results"},"content":{"rendered":"<div style=\"font-family: Verdana; text-align: justify;\">\n<p>A common feature that QTP testers are often asked to implement is to capture the application screenshot every time an error occurs during test run. This is definitely a good to have feature in your automation framework because &#8211;<\/p>\n<p><strong>a)<\/strong> When a script fails, you would have a proof that it failed due to<!--more--> an application issue and not due to your script, and<\/p>\n<p><strong>b)<\/strong> with the error screenshot, the developers usually find it easier to identify\/fix the issue.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" title=\"Capture Screenshot in QTP\" src=\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/capture-bitmap-qtp.png\" alt=\"Capture Screenshot in QTP\" width=\"555\" height=\"188\" \/><\/p>\n<h3><strong>How to capture application screenshot<\/strong><\/h3>\n<p><span style=\"text-decoration: underline;\">QTP provides a method called CaptureBitmap that can capture the image of either an object within the application or the entire screen\/desktop and save it in any desired location.<\/span> The image is saved as <strong>.png<\/strong> or <strong>.bmp<\/strong> file depending upon the file extension provided during the function call. The object is captured as it appears in the application when the method is performed. If only a part of the object is visible, then only the visible part is captured. Let&#8217;s see some examples on how this functionality can be used &#8211;<\/p>\n<p><strong>Example 1: Capture the image of a WebTable object and save it in the test&#8217;s run result folder (relative path).<\/strong><\/p>\n<p><code><span style=\"color: #0000ff;\">Function<\/span> fnCaptureBitmap1<br \/>\nBrowser(<span style=\"color: #800000;\">\"brBrowser\"<\/span>).Page(<span style=\"color: #800000;\">\"pgPage\"<\/span>).WebTable(<span style=\"color: #800000;\">\"tblResults\"<\/span>).CaptureBitmap <span style=\"color: #800000;\">\"webtable.bmp\"<\/span><br \/>\n<span style=\"color: #0000ff;\">End Function<\/span><\/code><br \/>\nIn the above function since the file name path is relative, the screenshot is saved in the test result folder. To save the image in some specific folder, the user needs to provide the complete\/absolute path of the folder.<\/p>\n<p><strong>Example 2: Capture the Browser image and save it in a specified folder (absolute path).<\/strong><\/p>\n<p><code><span style=\"color: #0000ff;\">Function<\/span> fnCaptureBitmap2<br \/>\nBrowser(<span style=\"color: #800000;\">\"brBrowser\"<\/span>).CaptureBitmap <span style=\"color: #800000;\">\"D:\/CaptureScreenShotDemo\/generic_image.png\"<\/span><br \/>\n<span style=\"color: #0000ff;\">End Function<\/span><\/code><br \/>\nWith this method the image gets stored in a specific location. Let&#8217;s suppose that there is already an image with the same name in the folder. With the above code, QTP will not overwrite the already existing image. To overwrite an already existing file, we need to set the <em>OverrideExisting<\/em> argument to True. Let&#8217;s see how this can be done.<\/p>\n<p><strong>Example 3: Capture Desktop Screenshot and save it in a specific folder (overwriting an image with same name, if any)<\/strong><\/p>\n<p><code><span style=\"color: #0000ff;\">Function<\/span> fnCaptureBitmap3<br \/>\nBrowser(<span style=\"color: #800000;\">\"brBrowser\"<\/span>).CaptureBitmap <span style=\"color: #800000;\">\"D:\/CaptureScreenShotDemo\/generic_image.png\"<span style=\"color: #000000;\">, <span style=\"color: #0000ff;\">True<\/span><\/span><\/span><br \/>\n<span style=\"color: #0000ff;\">End Function<\/span><\/code><br \/>\nIn this case, if an image with name generic_image.png already exists in the CaptureScreenShotDemo folder, running the above code will overwrite the previous image.<\/p>\n<p>&nbsp;<\/p>\n<h3><strong>How to display the application screenshot in the test run results<\/strong><\/h3>\n<p>Reporter.ReportEvent method of QTP provides an optional argument<em> ImageFilePath, <\/em>that can be used to display the screenshot in the QTP Test Results. Let&#8217;s see how this can be done.<\/p>\n<p><strong>Example 4: Capture Desktop Screenshot and display the image in the test run results<\/strong><\/p>\n<p><code><span style=\"color: #0000ff;\">Function<\/span> fnDisplayBitmapInTestResults<br \/>\nBrowser(<span style=\"color: #800000;\">\"brBrowser\"<\/span>).CaptureBitmap <span style=\"color: #800000;\">\"D:\/CaptureScreenShotDemo\/image.png\"<\/span>, <span style=\"color: #0000ff;\">True<\/span><br \/>\nReporter.ReportEvent micDone, <span style=\"color: #800000;\">\"Image\"<\/span>, <span style=\"color: #800000;\">\"Image\"<\/span>, <span style=\"color: #800000;\">\"D:\/CaptureScreenShotDemo\/image.png\"<\/span><br \/>\n<span style=\"color: #0000ff;\">End Function<\/span><\/code><\/p>\n<p><span style=\"text-decoration: underline;\">Notes:<\/span><br \/>\n<span style=\"text-decoration: underline;\">1.<\/span> You cannot load images from Quality Center.<br \/>\n<span style=\"text-decoration: underline;\">2.<\/span> If you include large images in the run results, it may impact performance.<br \/>\n<span style=\"text-decoration: underline;\">3.<\/span> If you specify an image as a relative path, QTP will first search the Results folder for the image and then the search paths specified in the Folders pane of the Options dialog box.<\/p>\n<\/div>\n<div style=\"font-family: Verdana,sans-serif; border: 1px solid #C8B560; padding: 3mm; background: #FFF8C6; text-align: center;\">\n<p>If you enjoyed this article, you can join our blog to get free email updates directly in your inbox.<\/p>\n<form style=\"text-align: center;\" action=\"http:\/\/feedburner.google.com\/fb\/a\/mailverify\" method=\"post\" onsubmit=\"window.open('http:\/\/feedburner.google.com\/fb\/a\/mailverify?uri=automationrepository\/feeds', 'popupwindow', 'scrollbars=yes,width=550,height=520');return true\" target=\"popupwindow\"><input style=\"width: 160px; height: 20px;\" onfocus=\"if (this.value == 'Enter Your Email Address') {this.value = '';}\" onblur=\"if (this.value == '') {this.value = 'Enter Your Email Address';}\" type=\"text\" value=\"Enter Your Email Address\" \/> <input type=\"hidden\" name=\"uri\" value=\"automationrepository\/feeds\" \/> <input type=\"hidden\" name=\"loc\" value=\"en_US\" \/> <input type=\"submit\" value=\"Join Us\" \/><\/p>\n<p style=\"text-align: justify;\">\n<\/form>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A common feature that QTP testers are often asked to implement is to capture the application screenshot every time an error occurs during test run. This is definitely a good to have feature in your automation framework because &#8211; a) When a script fails, you would have a proof that it failed due to<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[48,49,47,46],"class_list":["post-673","post","type-post","status-publish","format-standard","hentry","category-qtp-concepts","tag-capturebitmap","tag-reporter-reportevent","tag-screenshot","tag-test-results"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to capture application screenshot and display it in test results - XX<\/title>\n<meta name=\"description\" content=\"Capture application screenshot using QTP&#039;s CaptureBitmap method. Display the captures screenshots in QTP Test Result Run using Reporter.ReportEvent method\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Anish Pillai\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/\",\"name\":\"How to capture application screenshot and display it in test results - XX\",\"isPartOf\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/capture-bitmap-qtp.png\",\"datePublished\":\"2011-11-12T22:53:41+00:00\",\"dateModified\":\"2011-11-12T22:54:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\"},\"description\":\"Capture application screenshot using QTP's CaptureBitmap method. Display the captures screenshots in QTP Test Result Run using Reporter.ReportEvent method\",\"breadcrumb\":{\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#primaryimage\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/capture-bitmap-qtp.png\",\"contentUrl\":\"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/capture-bitmap-qtp.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.automationrepository.com\/wordpress\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to capture application screenshot and display it in test results\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#website\",\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/\",\"name\":\"XX\",\"description\":\"\\r\\nasas\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20\",\"name\":\"Anish Pillai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g\",\"caption\":\"Anish Pillai\"},\"description\":\"Find more about Anish Pillai on Google+\",\"sameAs\":[\"http:\/\/www.automationrepository.com\"],\"url\":\"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to capture application screenshot and display it in test results - XX","description":"Capture application screenshot using QTP's CaptureBitmap method. Display the captures screenshots in QTP Test Result Run using Reporter.ReportEvent method","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/","twitter_misc":{"Written by":"Anish Pillai","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/","url":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/","name":"How to capture application screenshot and display it in test results - XX","isPartOf":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#primaryimage"},"image":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#primaryimage"},"thumbnailUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/capture-bitmap-qtp.png","datePublished":"2011-11-12T22:53:41+00:00","dateModified":"2011-11-12T22:54:09+00:00","author":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20"},"description":"Capture application screenshot using QTP's CaptureBitmap method. Display the captures screenshots in QTP Test Result Run using Reporter.ReportEvent method","breadcrumb":{"@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#primaryimage","url":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/capture-bitmap-qtp.png","contentUrl":"https:\/\/www.automationrepository.com\/wordpress\/wp-content\/uploads\/ar\/capture-bitmap-qtp.png"},{"@type":"BreadcrumbList","@id":"https:\/\/www.automationrepository.com\/wordpress\/2011\/11\/how-to-capture-application-screenshot-using-qtp\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.automationrepository.com\/wordpress\/"},{"@type":"ListItem","position":2,"name":"How to capture application screenshot and display it in test results"}]},{"@type":"WebSite","@id":"https:\/\/www.automationrepository.com\/wordpress\/#website","url":"https:\/\/www.automationrepository.com\/wordpress\/","name":"XX","description":"\r\nasas","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.automationrepository.com\/wordpress\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/7a35710e1ce89e5fb481be88fcd6cd20","name":"Anish Pillai","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.automationrepository.com\/wordpress\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8aa984de2295c3c4078fa48f6ba5d91e7c849b1a27a11dca24c6f11dd673ba14?s=96&d=mm&r=g","caption":"Anish Pillai"},"description":"Find more about Anish Pillai on Google+","sameAs":["http:\/\/www.automationrepository.com"],"url":"https:\/\/www.automationrepository.com\/wordpress\/author\/anish\/"}]}},"_links":{"self":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/673","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/comments?post=673"}],"version-history":[{"count":26,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/673\/revisions"}],"predecessor-version":[{"id":699,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/posts\/673\/revisions\/699"}],"wp:attachment":[{"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/media?parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/categories?post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.automationrepository.com\/wordpress\/wp-json\/wp\/v2\/tags?post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}