【发布时间】:2016-04-25 22:03:14
【问题描述】:
我正在 UFT 中运行脚本,我想将结果写入 Excel 工作表。我该怎么办? 我运行的每个测试都会有一个测试 ID 和一个通过或失败状态。
【问题讨论】:
标签: hp-uft
我正在 UFT 中运行脚本,我想将结果写入 Excel 工作表。我该怎么办? 我运行的每个测试都会有一个测试 ID 和一个通过或失败状态。
【问题讨论】:
标签: hp-uft
我认为最简单的方法是将数据写入内置的DataTable,然后将DataTable导出到excel文件。
例如...
首先,添加一列(也称为参数)。这也将第一条数据记录添加到列中。
'add a new column
DataTable.GetSheet("Global").AddParameter "TestResult", passOrFail
那么,如果您需要添加更多记录...
currentRow = DataTable.GetCurrentRow
DataTable.SetCurrentRow = currentRow + 1
DataTable.Value("TestResult","Global") = AnotherPassOrFail
完成后,只需将数据表导出到 Excel 工作表
DataTable.Export "c:\filename.ext"
你去。
【讨论】:
在某个位置(例如:“C:\TestResults\”文件夹)创建带有“测试 ID”、“测试结果”列的 Excel 工作表。
创建一个函数,将每个测试的测试结果写入 Excel 工作表
在每个脚本的末尾调用该函数
Function WriteResulttoExcel(ID, TestResult, SheetPath)
'Creating the Excel Object
set objExcel = createobject("excel.application")
'Creating the Workbooks object
set objWB = objExcel.workbooks.open (SheetPath)
'Creating the sheet object
set objsheet = objwb.worksheets(1)
' Write test results to excel sheet
rws=objsheet.UsedRange.Rows.count
objsheet.cells(1,rws+1).Value= ID
objsheet.cells(2,rws+1).Value= TestResult
'Saving the workbook after changes
objWb.save
'closing the workbook
objWB.close
'Quit the Excel and destroying the Excel object
objExcel.Quit
set objExcel=nothing
End Function
【讨论】: