How to use HTML in Report output

Hi,

when using the Reporter.ReportEvent method, all we can insert is simple text strings.

No HTML code would pass through (you’ll get a string with HTML tags in the output XML).

But there is a way to use HTML in the report, so the Result Viewer (or other viewers) would show it.

first, we need to write function that make it possible:

Function HTMLReport(strStatus, strStepName, strMessage)
Set objDict = CreateObject(“Scripting.Dictionary”) ‘ a dictionary object
objDict(“Status”) = strStatus ‘ set the object properties
objDict(“PlainTextNodeName”) = strStepName
objDict(“StepHtmlInfo”) = strMessage ‘here is where the HTML code goes
objDict(“DllIconIndex”) = 206
objDict(“DllIconSelIndex”) = 206
objDict(“DllPAth”) = “C:\Program Files\Mercury Interactive\QuickTest Professional\bin\ContextManager.dll” ‘of course, you need the right path of the bin folder

objDict(“DllPAth”) = Environment(“ProductDir”) &  “\bin\ContextManager.dll”

Reporter.LogEvent “User”, objDict, Reporter.GetContext ‘report the custom HTML
End Function

now, all we need is to call that function with the appropriate parameters:

strHTML  = “<TABLE border=1><TR><TH>This is <b>QTPQA</b> blog!</TH></TR>”
strHTML = strHTML & “<TR><TD>Sunday</TD></TR>”
strHTML = strHTML & “<TR><TD>Monday</TD></TR>”
strHTML = strHTML & “<TR><TD>Tuesday</TD></TR>”
strHTML= strHTML & “</TABLE>”

‘and the call to the function:

HTMLReport micPass, “HTML Report Example”, strHTML

and this is what you get:

HTML in Report


Have fun!

3 thoughts on “How to use HTML in Report output

  1. i did this code and i got an error when i tried to view the results using the result run report in alm 11. I get the following message: the start tag ‘br’ on line 1 does not match the end tag of ‘body’. line 1 position 147.
    i’m not using any br tag in the code.
    thanks in advanced

    1. I’m sorry, I tried it with QC 9.2 only because that is what I have and it works fine.
      BTW, I found this tip somewhere, I did not invent it.

      Anyway, I hope it could be used by you for results regardless of QC/ALM.

Leave a reply to qtpqa Cancel reply