Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts

How to add result as HTML table format in QTP test results

We can use reporter.logevent method as explained in code/functions below to add results in  tabular format in QTP test results. Below is an example on how to use reporter.logevent


Public Function func_createHTMLTableFromExcel(strDataFile,strWorksheetName)

Set objXlHandle = Createobject("Excel.Application")

 objXlHandle.visible = false

Set objExcelWB = objXlHandle.Workbooks.Open(strDataFile)

Set objExcelWS = objExcelWB.Worksheets(strWorksheetName)

'Getting column and row count 

 strColumnCount = objExcelWS.UsedRange.Columns.Count

 strTotRows = objExcelWS.UsedRange.Rows.Count

strTable = "<table border=""""2"""">"

'Creating a html table based on content of the excel file

For j=1 to strTotRows

strTable = strTable & "<tr>"

For i=1 to strColumnCount

 strData = Trim(objExcelWS.Cells(j,i))

 strTable= strTable & "<td>"& strData &"</td>"

Next

strTable =strTable & "</tr>"

Next

strTable = strTable & "</table>"

Call reportinQTPhtmlContent(strTable)

'Closing the workbook

 objExcelWB.Close

End Function


Public Function reportinQTPhtmlContent(strTable)

Set objdict = CreateObject("Scripting.dictionary")

objdict.Add "Status", micdone

objdict.Add "NodeName", "Table Data"

objdict.Add ("StepHtmlInfo"), strTable

Reporter.LogEvent "User", objdict, Reporter.GetContext

End function

No comments:

Post a Comment