While building our web site to speed our analysis of our daily regression tests, we needed to access result data quickly. Our failed error messages and snapshots of crashes were trapped inside QTP result logs. As anyone who has looked into these logs knows, they were not designed for casual deciphering.
Rather than fight the HP logs, file structures, compression methods, and database, we went around it. We started collecting our own copy of key information -- free and easy for us to use. We are able to build this site with crash snapshots and error messages:
We developed shadow methods for collecting information. When a test step fails or when something crashes, QTP writes information to its log, and we write a copy of the same information to our database or file server.
Rather than fight the HP logs, file structures, compression methods, and database, we went around it. We started collecting our own copy of key information -- free and easy for us to use. We are able to build this site with crash snapshots and error messages:
We developed shadow methods for collecting information. When a test step fails or when something crashes, QTP writes information to its log, and we write a copy of the same information to our database or file server.
To support this, we created a database table that stores
error messages and is keyed off cycle and run ids and wrote a ShadowFailMessage method for our QTP function
library:
Here is the code for the subroutine we referenced:
To make this work, we added a reference to the ShadowFailMessage subroutine after each fail (it would have been more elegant to have opened the Reporter class and added the additional functionality, but this is VBScript, not Ruby L). This takes the error message content and writes it to a database table along with other information needed to associate the message with the right test. The pattern looks like this:
Reporter.ReportEvent micFail, title_of_error, “Expected: “ & expected_value & “ – Actual: “ & actual_value
ShadowFailMessage title_of_error, actual_value, expected_value
Here is the code for the subroutine we referenced:
Sub ShadowFailMessage(nameOfDataValue, actual, expected)
actual = Replace(actual,"'","''")'escape single quotes that will break the SQL query
expected = Replace(expected,"'","''")
On Error Resume Next
cycle_id = QCUtil.CurrentTestSet.ID
run_id = QCUtil.CurrentRun.ID
If expected ="" Then
fail_message = Left((nameOfDataValue & ": " & "Error message: " & actual), 500)
Else
fail_message = Left((nameOfDataValue & ": " & "Expected: " & expected & "; " & "Actual: " & actual), 500)
End If
'Write to the cfc_SNAPSHOTS table. set sn_type to 1 to indicate error message
strSQL = "INSERT INTO test_snapshots (sn_cycle_id, sn_run_id, sn_snapshot_url, sn_type) " &_
"VALUES (" & cycle_id &"," & run_id & ",'" & fail_message & "', 1)"
objRecordSet = GetRecordSet(strSQL, "QC")
On Error GoTo 0
End Sub
We also have Shadow subroutines for crash snapshots and actual/expected QTP datatables (for verifying reports and tables).
actual = Replace(actual,"'","''")'escape single quotes that will break the SQL query
expected = Replace(expected,"'","''")
On Error Resume Next
cycle_id = QCUtil.CurrentTestSet.ID
run_id = QCUtil.CurrentRun.ID
If expected ="" Then
fail_message = Left((nameOfDataValue & ": " & "Error message: " & actual), 500)
Else
fail_message = Left((nameOfDataValue & ": " & "Expected: " & expected & "; " & "Actual: " & actual), 500)
End If
'Write to the cfc_SNAPSHOTS table. set sn_type to 1 to indicate error message
strSQL = "INSERT INTO test_snapshots (sn_cycle_id, sn_run_id, sn_snapshot_url, sn_type) " &_
"VALUES (" & cycle_id &"," & run_id & ",'" & fail_message & "', 1)"
objRecordSet = GetRecordSet(strSQL, "QC")
On Error GoTo 0
End Sub
We also have Shadow subroutines for crash snapshots and actual/expected QTP datatables (for verifying reports and tables).
We no longer complain about the limitations of our existing tools – we own the solutions to our own problems. In our case, we used open-course tools like Ruby and Sinatra libraries to develop our own applications for using our test results. I have even started to like HP's problems. They have become excuses for some fun coding -- too bad we are paying for the problems though.