The code below will show you how to do this from within QTP. There are a few things to bear in mind:
- Our framework uses a custom reporting function through which all pass, fails, warnings etc are passed. Therefore it allows us to single out errors and post them back to QC.
- The QC field has a limitation of 255 chars, so we use this only to post the last error. Our QC field is called "Error Details".
- It's used to give us a quick snapshot as to the cause of the failure so we can determine to rerun or investigate the result further. This isn't intended to replace results analysis - we don't "pass" tests until we've fully investigated the results.
The code:
Sub WriteToQCExecutionGrid(strValue)
Const QCFieldName = "Error Details" 'change this to match your QC field name
Dim strThisTestName
Dim objTSTestFactory
Dim objField
Dim objTestList, objTest
Dim blnTestFound : blnTestFound = false
Dim strInternalFieldName
Dim objQCTestInstance
'setup default values
strInternalFieldName = ""
'See if we're connected to QC
If not qcutil.IsConnected Then
exit sub
End if
'See it we're connected to a test lab test set
If (qcutil.CurrentTestSet is nothing) Then
exit sub
end if
'Connect to the ts test factory - this represents the execution grid
Set objTSTestFactory = qcutil.CurrentTestSet.TSTestFactory
'Now search through the fields to see if we can find one called Error Details"
For each objField in objTSTestFactory.Fields
If (objField.Property.UserLabel = QCFieldName) then
strInternalFieldName = objField.Name
Exit for
End if
Next
'If we didn't find the field name, exit
If strInternalFieldName = "" Then exit sub
strThisTestName = qcutil.CurrentTestSetTest.Name
'Now find this test in the execution grid
Set objTestList = objTSTestFactory.NewList("")
For Each objTest In objTestList
If (objTest.Name = strThisTestName) Then
'Test was found, so update flag and exit
Set objQCTestInstance = objTest
blnTestFound = true
Exit for
End If
Next
If not blnTestFound Then
exit sub
End If
'objQCTestInstance will now hold the test that we need to update
objQCTestInstance.Field(gstrInternalFieldName) = strValue
objQCTestInstance.post
End Sub
Example:
Call WriteToQCExecutionGrid("Failed to Load Webpage")
No comments:
Post a Comment