使用 UFT 将测试结果写入 excel sheet

Write test results to excel sheet using UFT

我正在使用 UFT 运行ning 脚本,我想将结果写入 excel sheet。我该怎么做? 我 运行 的每个测试都会有一个测试 ID 和一个通过或失败状态。

我认为最简单的方法是将数据写入内置的 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 sheet

DataTable.Export "c:\filename.ext"

给你。

在某些位置(例如:"C:\TestResults\" 文件夹)创建 Excel sheet 和 "Test ID"、"Test Result" 列。

创建一个函数,将每个测试的测试结果写入 Excel sheet

在每个脚本结束时调用该函数

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