Tuesday, October 4, 2011

Export QTP Result as a HTML Page

The Quick Test Professional has an in built functionality to Export Test Results in PDF, Excel or HTML file but if the user want to Export the Test Result via descriptive programming and user defined function than the below code will be helpful.

This below simple code for "Export QTP Result as a HTML Page" is modifiable and developed with VB Script.

Function Declaration :
Public Function GenerateHTMLReport(ByVal inputXML, ByVal inputXSL, ByVal outputFile)
   sXMLLib = "MSXML.DOMDocument"
   Set xmlDoc = CreateObject(sXMLLib)
   Set xslDoc = CreateObject(sXMLLib)
   xmlDoc.async = False
   xslDoc.async = False

   xslDoc.load inputXSL

   xmlDoc.load inputXML

   outputText = xmlDoc.transformNode(xslDoc.documentElement)

   Set FSO = CreateObject("Scripting.FileSystemObject")
   Set outFile = FSO.CreateTextFile(outputFile,True)
   outFile.Write outputText
   outFile.Close
   Set outFile = Nothing
   Set FSO = Nothing
   Set xmlDoc = Nothing
   Set xslDoc = Nothing
   Set xmlResults = Nothing

 End Function

Use of Function :
Dim sResultsXML, sDetailedXSL
sResultsXML is for define full path of the Result.xml file.
sDetailedXSL is for QTP inbuilt PDetails.xsl file for format the Result.xml file.

For Example :
sResultsXML = "C:\Temp\TempResults\Report\Results.xml"
sDetailedXSL = "C:\Program Files\HP\QuickTest Professional\dat\PDetails.xsl"

Function Call :
GenerateHTMLReport sResultsXML, sDetailedXSL, "Path for save the Exported HTML file"