Wednesday, October 2, 2013

Let My Fail Pics Go

In Free Your QTP TestResults, we shared how we create a shadow set of test results that we can write to own database and can use however we want. We are freed of the shackles of the QTP test results viewer.  We didn’t stop there.  We also freed the snapshots that we take when QTP crashes or hits some wall of pain.

Before using the shadow data strategy, we had QTP take a picture that we could see in the result log.  Did something like this:

setting("SnapshotReportMode") = 0 'take a picture
Some test object.Exist(0)
setting("SnapshotReportMode") = 1 ‘turn off the pic taking

As I said, this did the job, but it also trapped the results in the result viewer.  We did some investigation on how to access the snapshots from Quality Center. There may be an easy way, but we didn’t find it.  What we found would have required us to uncompress the image file before using it and it is hard to find anyway.

To set pics of our failures free, we implemented ShadowSnaphot:

Sub ShadowSnapshot()
    On Error Resume Next
    cycle_id = QCUtil.CurrentTestSet.ID
    run_id = QCUtil.CurrentRun.ID
    strUrl = "\\somefileserver\Testing\QC\snapshots\" & CreateTimeStamp & "_" & run_id & ".png"
    Desktop.CaptureBitmap strUrl 'Write the image to file server
    'publish the url to the result viewer
    Reporter.ReportEvent micDone, "View Desktop Snaphot""See the desktop here: " & strUrl
    'Write to our database 
    strSQL = "INSERT INTO cfc.test_snapshots (sn_cycle_id, sn_run_id, sn_snapshot_url, sn_type) " &_
              "VALUES (" & cycle_id &"," & run_id & ",'" & strUrl & "', 0)"
    objRecordSet = GetRecordSet(strSQL, "QC")
    On Error GoTo 0
End Sub

We save the snapshot to a file server and we write the information we need to find our snapshot to a database table. We use ShadowSnapshot method before we exit out of a test and when the recovery scenario is kicked off.

This has been working out great.  Our results are saved as .png files which is lightweight and easy to use.  For example, we can easily view our images in web apps that we build to make our lives easier.  Personal happiness with Shadow snapshots.

Extra bonus benefit:  We are troubleshooting some problems with our test execution.  Since we are using ShahowSnapshot on most test fails, and the method adds a pic file to our file server, we can write a utility to troll for new pics in the directory and display them in real time.  Ruby project. Will share more with this soon.

No comments:

Post a Comment