Search This Blog

Friday, September 9, 2011

QTP & QC -> Code for function to call a reporter event with micfail

'****************************************************************************************************************************
'Function Name : Fun_ReportFailure
'Description   Use this function to call a reporter event with micfail and have the error snapshot in result directory/ upload to QC run if connected
'Parameters     strStepName , strDescription , objSnapshot  
'Return Val ue     NA
' Example    Fun_ReportFailure "Main Menu" , "Header displayed" , Browser("main")  
'****************************************************************************************************************************
Function Fun_ReportFailure(strStepName , strDescription , objSnapshot)
   If  Not objSnapshot Is Nothing Then
  'Call the micFail reporter event and associated to the report 

  Extern.Declare micLong, "SetForegroundWindow","user32.dll", "SetForegroundWindow", micLong
  Extern.SetForegroundWindow objSnapshot.Object.HWND
  wait(2)
  'Capture snapshot of the object provided
  objSnapshot.CaptureBitmap Environment("ResultDir") & "\" & FunTestIterationNumber & "_" & strStepName & ".png" , True

  Reporter.ReportEvent  micFail  , FunTestIterationNumber & "_QTP_" & strStepName , strDescription , Environment("ResultDir") & "\" & FunTestIterationNumber & "_" & strStepName & ".png"
 Else
  'Call the micFail reporter event and associated to the report
  Reporter.ReportEvent  micFail  , FunTestIterationNumber & "_QTP_" & strStepName , strDescription 
 End If
End Function

No comments:

Post a Comment