QTP generate it's results in an XML format. We can use the inbuilt result convertor to convert these into any format we want, but for that we need to have the RunResultsViewer installed on the system. But we can also convert these results into an HTML file manually. In order to convert this XML to any other format we need to use the XSL style sheet to define the conversion.
XSL is a Stylesheet language which can be used to transform an XML according to the specification. 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 3 different XSL files which would be located in the following folder - "C:\Program Files (x86)\HP\QuickTest Professional\dat\"
PDetails.xsl - for getting the detailed results in HTML format
PShort.xsl - for getting the short results in HTML format
PSelection.xsl - for getting the selective results in HTML format
The PSelection.xsl file requires input arguments for the XSL and the other 2 can be directly loaded into the XML.
We can either refer these XSL files from the default directory [dat] or copy them to any folder we like, and then reference from there. Also, in order for the results to be displayed correctly the PResults.css [also located in the dat folder] file should be present in the same folder as the output HTML file. Hence, in order to avoid creating all the new result HTML files in the dat folder itself, its better to copy all the required files to a different directory and then work off of that one.
Below is the function that would do this conversion.
'''--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
'' Function Name: funcConvertResultsXMLtoHTML
'' Description: This function will convert the QTP Results.xml into HTML format, with Detailed or Short versions.
'' This can be called from within QTP, or an external VbScript
'' Input Parameters: sInputResultsXML - The path of the QTP Results.xml
'' sXSLType - The XSL type, based on which the results will be converted to either Detailed or Short version
'' sOutputHTMLPath - The complete path where the HTML result file needs to be created
'' Output Parameters: None
'' Author: Ashish Jaiswal
'''--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Function funcConvertResultsXMLtoHTML (sInputResultsXML, sXSLType, sOutputHTMLPath)
''Creating an instance for the DOMDocument Class of the MS XML Parser [MSXML.dll]
Set oXMLDoc = CreateObject("MSXML.DOMDocument")
Set oXSLDoc = CreateObject("MSXML.DOMDocument")
''Since a file is loaded asynchronously by default by the parser, we set it to false
''By setting the document's Async property to False, the parser will not return control to your code until the document is completely loaded and ready for manipulation. If you leave it set to True, you will need to either examine the ReadyState property before accessing the document or use the DOMDocument's events to have your code notified when the document is ready. Using the default value may cause issues during reading and writing to file, hence, its best to keep things simple, and let it be False.
oXMLDoc.ASync = False
oXSLDoc.ASync = False
''Opening the document via the Load method, by specifying the path of the input XML and XSL
''The XML parser can load XMLs from the local disk, over the network using the UNC path, or via a URL
oXSLDoc.Load sXSLType
oXMLDoc.Load sInputResultsXML
''Processing the entire XML (it processes all the nodes and the children) using the specified XSL Style Sheet, and then returning the transformation
sTransformedXML = oXMLDoc.transformNode(oXSLDoc.documentElement)
''Creating a new file to hold the transformed XML data - the output HTML file, and enabling overwriting the file with True
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oOutputHTML = oFSO.CreateTextFile(sOutputHTMLPath,True)
''Writing the transformed text to the HTML file
oOutputHTML.Write sTransformedXML
''Saving the file finally
oOutputHTML.Close
''Destroying the objects
Set oOutputHTML = Nothing
Set oFSO = Nothing
Set oXMLDoc = Nothing
Set oXSLDoc = Nothing
End Function
'''--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Now to use the function...
''Path of the Results file which needs to be converted
sResultsXMLPath = "C:\auto\Results.xml"
''Path of the XSL for detailed version
sDetailedXSLPath = "C:\auto\PDetails.xsl"
''Path of the XSL for short version
sShortXSLPath = "C:\auto\PDetails.xsl"
Call funcConvertResultsXMLtoHTML (sResultsXMLPath, sDetailedXSLPath, "C:\auto\Results_Detailed.html")
Call funcConvertResultsXMLtoHTML (sResultsXMLPath, sShortXSLPath, "C:\auto\Results_Short.html")