Tuesday, March 30, 2010

Convert Test Result from XML format to HTML Format

We can convert QTP Test Results from XML format to HTML Format with code as well as with wizard(File -->Export Report). use code with below instructions.
1. Create one script with conversion code
2. which script result do you want to convert, collect that script result path from Results Location in Run Wizard and use same in first script.
3. create Batch file with above two scirpts and execute same.

QTP Test Result Conversion Code:-
Dim xmlSource,xmlXForm, strErr, strResult,fso, file, strPath
Const ForWriting = 2
Set xmlSource = CreateObject("MSXML.DOMDocument")
Set xmlXForm = CreateObject("MSXML.DOMDocument")
xmlSource.validateOnParse = True
xmlXForm.validateOnParse = True
xmlSource.async = False
xmlXForm.async = False
xmlSource.Load "C:\REsultConversion\Res1\Report\Results.xml"
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & " line: " & _ xmlSource.parseError.Line & " col: " & _ xmlSource.parseError.linepos & _ " text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error loading the XML"
End If
' This loads the XSLT transform
'Here you need to update your Xsl file
xmlXForm.Load "C:\Program Files\HP\QuickTest Professional\dat\PDetails.xsl"
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf strErr = strErr & xmlSource.parseError.reason & " line: " & _ xmlSource.parseError.Line & " col: " & _ xmlSource.parseError.linepos & _ " text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error loading the Transform"
End If
strResult = xmlSource.transformNode(xmlXForm)
If Err.Number <> 0 Then
strErr = Err.Description & vbCrLf
strErr = strErr & xmlSource.parseError.reason & _ " line: " & xmlSource.parseError.Line & _ " col: " & xmlSource.parseError.linepos & _ " text: " & xmlSource.parseError.srcText
MsgBox strErr, vbCritical, "Error executing the Transform"
End If
Set fso = CreateObject("Scripting.FileSystemObject")
'Here you need to update your Output files '
strPath = "C:\testResult2.html"
' open the file
Set file = fso.opentextfile(strPath, ForWriting, True)
' write the info to the file
file.write strResult
' close and clean up
file.Close