Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

UFT test information and failure reason from result.xml file

While running the UFT test in batch,we need to capture executed test information including testname, test execution status and reason for failure if any in the test execution. 
Below code in vbscript can be used to extract required information from results file (result.xml) in UFT and parsing the information in xml file using MSXML.DomDocument and Microsoft.XMLDOM


xmlFilePath = "c:\Results.xml"

Set xmlDoc = CreateObject("MSXML.DomDocument")
If xmlDoc.Load (xmlFilePath) Then
'Get the test name
 Set objNode = xmlDoc.GetElementsByTagName("DName")
 .TestName = objNode(0).Text
 Set objNode = xmlDoc.GetElementsByTagName("Summary")

 'Last Node with tagName "Summary" has details of Pass/Fail status
 Set Node = objNode(objNode.Length - 1)

 intStepsPassed = Node.getAttribute("passed")
 intStepsWarning = Node.getAttribute("warning")

 ''in case of failures get the testfailureReason
 If Cint(intStepsFailed) > 0 Then
  strFailureReason = getFailureReason(xmlFilePath)
 End if
 Set FSO = Nothing
 Set xmlDoc = Nothing
End If

Public function getFailureReason(strFileName)
 Set xmlDoc = CreateObject("Microsoft.XMLDOM")
 xmlDoc.async = False
 strErrorMsg = ""
 booleanxmlParse = xmlDoc.load(strFileName)
 if(booleanxmlParse) then
  xmlDoc.setProperty "SelectionLanguage", "XPath"
  set xmlDoc_node = xmlDoc.selectNodes("//Step//NodeArgs[@status='failed']")
  for each node in xmlDoc_node
   strNode = node.parentNode.getattribute("rID")
   set TCNode = xmlDoc.selectSingleNode("//Step[@rID='" + strNode + "']/Details")
   strErrorMsg=strErrorMsg & TCNode.text
  Next
 End If
 getFailureReason = strErrorMsg 
End Function

No comments:

Post a Comment