Blog to understand automation concepts in QTP, Selenium Webdriver and Manual Testing concepts
How to create a database checkpoint in QTP
How to add result as HTML table format in QTP test results
Labels:
QTP,
qtp Scripts,
Test Scripts
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
QTP Script to convert content of excel into a html document
Labels:
QTP,
qtp Scripts,
Test Scripts
Suppose I have some data in excel file and I want to create a html table from the excel file content. Below code can create a html table based on the content of an excel file.We can understand how to create a html file using scripting.filesystemObject in QTP.
Example of how to call the function:
func_createHTMLTableFromExcel "E:/test.xlsx","Sheet1","e:/ht.htm"Code for the function:
Public Function func_createHTMLFromExcel(strDataFile,strWorksheetName,strHTMLFile)
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>"
set objFSO=Createobject("scripting.FileSystemObject")
set objtxt = objFSO.createTextFile(strHTMLFile)
objtxt.write(strTable)
'Closing the workbook
objExcelWB.Close
set objFSO =nothing
End Function
Subscribe to:
Posts (Atom)