Search This Blog

Friday, September 9, 2011

QTP & QC ->Code to capture error message displayed in web dialog page

'****************************************************************************************************************************
'Function Name : Fun_CheckForErrorMessage
'Description    Use this function to capture error message displayed in web dialog page
'Parameters   NA         
'Return Val ue     True - If error exists :: False - If no error
'Registerd To  NA
'Base Project  EFAS
' Ex:ample    Fun_CheckForErrorMessage()
'****************************************************************************************************************************
Function Fun_CheckForErrorMessage()
 wait(3)
 Dim desTemp,objChildWinCol,intWindowCounter,intPageCounter,objChildPageCol,objMessageDIV,objStaticCol,intStaticCount,objButtonCol
 strErrorMessage = ""
 Fun_CheckForErrorMessage = False
 'Create temp description object to get the collection
 Set desTemp = Description.Create
 'Desktop object child collection
 Set objChildWinCol = Desktop.ChildObjects(desTemp)
 'Identify the Error window dialog
 For intWindowCounter = 0 to objChildWinCol.Count - 1
  'Identify error in a dialog window
  If  objChildWinCol(intWindowCounter).GetROProperty("nativeclass") = "Internet Explorer_TridentDlgFrame"  And   Trim(objChildWinCol(intWindowCounter).GetROProperty("title")) = "-- Webpage Dialog" Then
   Set objChildPageCol = objChildWinCol(intWindowCounter).ChildObjects(desTemp)
   'Get the error message from the error dialog page
   For intPageCounter = 0 to objChildPageCol.Count - 1
    If  objChildPageCol(intPageCounter).GetROProperty("micclass") = "Page" Then
     'Identify the error message area and get the innertext     
     If Instr(1 , objChildPageCol(intPageCounter).Object.body.InnerHTML , "error_icon" ) > 0 Then
      'Capture bitmap of the error
      objChildPageCol(intPageCounter).CaptureBitmap Environment("ResultDir") & "\" & FunTestIterationNumber & "_" & "Error snaphot" & ".png" , True
      Reporter.ReportEvent micFail , "Error" , "Error snapshot" , Environment("ResultDir") & "\" & FunTestIterationNumber & "_" & "Error snaphot" & ".png"
      Set objMessageDIV = objChildPageCol(intPageCounter).Object.GetElementsByTagName("DIV")   
      strErrorMessage =  objMessageDIV(objMessageDIV.Length - 1).innerText
      Fun_CheckForErrorMessage = True
     Else
      Fun_CheckForErrorMessage = False
     End If    
     Exit For
    End If
   Next
   'Close the error window
   objChildWinCol(intWindowCounter).Close
   Exit For
  'Identify error in a message box
  ElseIf objChildWinCol(intWindowCounter).GetROProperty("nativeclass") = "#32770"  And   Trim(objChildWinCol(intWindowCounter).GetROProperty("text")) = "Microsoft Internet Explorer" Then
   'Capture bitmap of the error
   objChildWinCol(intWindowCounter).CaptureBitmap Environment("ResultDir") & "\" & FunTestIterationNumber & "_" & "Error snaphot" & ".png" , True
   Reporter.ReportEvent micFail , "Error" , "Error snapshot" , Environment("ResultDir") & "\" & FunTestIterationNumber & "_" & "Error snaphot" & ".png"
   'Get the collection of  message box objects
   Set objStaticCol = objChildWinCol(intWindowCounter).ChildObjects(desTemp)
   For intStaticCount = 0 to objStaticCol.Count -1
    'get the collection of static objects text
    If objStaticCol(intStaticCount).GetRoProperty("micclass") = "Static" Then
     strErrorMessage = strErrorMessage & objStaticCol(intStaticCount).GetRoProperty("text")
     Fun_CheckForErrorMessage = True
    End If
   Next
   'close the error window
   objChildWinCol(intWindowCounter).Close
   Exit For
  End If
 Next
End Function

No comments:

Post a Comment