Capture Screenshots in UFT and Save them in Word Doc

Having test results as proof of testing is an essential thing. In this article, we will learn how to capture screenshots in UFT during automation script execution and insert them sequentially in a word document.UFT does have a method CaptureBitmap that can be used to capture the screenshot of the entire test application or any specific object of the test application and save it to the desired place. We will write two custom methods that will be used to capture screenshots at runtime and insert them into a word document in the same order they were captured.

capture screenshots in uft

Capture Screenshots In UFT

You will have to create two user-defined functions for the purpose of capturing screenshots and inserting those into the word document. If you know more about user-defined functions please refer to my post Create User-Defined Functions in UFT. Copy the following functions into your common function library and declare a global variable with the name strCapImages
  • CaptureAUTScreenShot
  • CopyImagesToWord
Modify the second line of the “CaptureAUTScreenShot” function to provide the parent object of the browser as per your actual test application. In my case, the browser object is Browser(“name:=.*mercury.*”). 

The following function will insert captured images into the word document.

Now create a script and call the CaptureAUTScreenShot function wherever you need to capture the screenshot of the test application and at the very last line of the script call the CopyImagesToWord function to insert all captured images in sequential order in the word document.
 
The following is the sample code for reference

Now you can run your test script and when the execution gets completed you can open the word document that was passed as a parameter in the CopyImagesToWord method. You can see all the captured screenshots have been inserted into the word document.

Recommended Posts

Leave a Reply