QTP generate it's results in XML format. These results are only accessible when the test case has finished execution. Any manipulation that you want to do with the results you can do that only outside of QTP (in case you are looking at the results of QTP script that just ran). This can be achieved by running you script from a external VBS which use QTP AOM for running the script. And once done you can access the script in the external VBS.
Coverting results to HTML:
XSL is a Stylesheet language which can be used to transform a XML in way we want it to be. The output could be a HTML file, a text file, a XML file etc...To do this transformation at run-time we need to load the XML and then the XSL into that and save the output. QTP comes with three different XSL files which are present in the below location
C:/Program Files/Mercury Interactive/QuickTest Professional/dat
PDetails.xsl - Detalied HTML Conversion
PShort.xsl - Short HTML conversion
PSelection.xsl - Selective HTML Conversion
The last one (PSelection.xsl) requires input arguments for the XSL and the first 2 can be simply loaded into the XML.
Code:
sResultsXML = "C:/Results.xml"
sDetailedXSL = "C:/Program Files/Mercury Interactive/QuickTest Professional/dat/PDetails.xsl"
sShortXSL = "C:/Program Files/Mercury Interactive/QuickTest Professional/dat/PDetails.xsl"
ApplyXSL sResultsXML, sDetailedXSL, "C:/Results_Detailed.html"
ApplyXSL sResultsXML, sShortXSL, "C:/Results_Short.html"
Public Function ApplyXSL(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
I have attached the outputs to the post. Just note one thing that in case you want the results to be displayed correctly then the PResults.css file should be present in the same folder as HTML.