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!

Advertisements