How to take a screenshot of application using QTP


I want to take a screen shot of application when error occurs & save it in a specific folder. Below code works but it doesnt take a screen shot of application, it takes a screen shot of QTP Code screen.

Function CaptureImage()
    Dim Date_Time
    Dim Myfile
    Myfile= Date_Time&".png"
    Myfile = Replace(Myfile,"/","-") 
    Myfile = Replace(Myfile,":","-")
    Myfile= "C:\"&Myfile 
    Desktop.CaptureBitmap Myfile, True
End Function

Best Solution

Dim ScreenName

  On Error Resume Next

  ScreenName = " "
  CurrentTime = "_Test_Case"&"_"& Day(Now)&"_"& Month(Now)&"_"& Year(Now)&"_"&

   Hour(Now)&"_"& Minute(Now)&"_"& Second(Now)

  ScreenShotName = "Name_of_the_Screen" &  CurrentTime & ".png"

  ScreenName ="Path where the Screenshot needs to be stored"&"\"&ScreenShotName

  Desktop.CaptureBitmap ScreenName,True

This should work.

Related Question