Thursday, April 8, 2010

QTP - Capture screen shot.

QTP - Capture screen shot.

During test execution, if any of the test cases got failed, it is always a best practice to capture the screen shot. This will help us to resolve the problem easily.

Following are the difficulties faced while capturing the screen shot using QTP.
1. Name to be assigned for each screen shot.
2. Where to store the screen shot files.
3. How to notify the user this particular screen shot belongs to a specific particular test case.

Attaching screen shot function that can be called when required.
1. Assign current time stamp as screen shot name.
2. Store the files in the specified folder. I have used global variable (gsFolderPath).
3. Mention the screen shot name generated in the step 1 in the test case using global variable (gsStatusMessageTestCase).


Function ScreenShot()
        Dim sDateTimeNow, sFilePath
        sDateTimeNow = funUnique()
        sFilePath = gsFolderPath & "ScreenShots\" & "ScreenShot_" &  funUnique() & ".png"
        Desktop.CaptureBitmap sFilePath, True
        gsStatusMessageTestCase = gsStatusMessageTestCase & " SCREEN SHOT ID " & sDateTimeNow & " # "
End Function

Function funUnique()
        funUnique = "QTP_" & funGetTimeStamp() & "_" & Environment("envsPlace")
End Function
Attaching screen shots folder screen shot.


Attaching test case screen shot, displaying the application screen shot details at the failed step.




Follow this link for actual implementation in the framework.



----

No comments:

Post a Comment