|
我用XP带的计算器做了一个简单的test,没考虑输出和输入参数这些问题,就只是为了说明QTP对xls文件的读写,我把要用到的xls文件也附上。我也是菜鸟,希望高手多多指点啊,大家共同学习进步嘛,代码如下:
Set xlApp = CreateObject("Excel.Application")
xlApp.application.visible=true
Set xlbook=xlApp.WorkBooks.Open("d:\nonodata.xls")
Set xlSheet = xlBook.Worksheets("Sheet1")
systemutil.Run "C:\windows\system32\calc.exe"
For i=2 to 5
input1= xlSheet.cells(i,2).value
expression = xlSheet.cells(i,3).value
input2= xlSheet.cells(i,4).value
expresult = xlsheet.cells(i,5).value
Window("计算器").Activate
Window("计算器").Type cstr(input1)
Window("计算器").WinButton("operator").SetTOProperty "text",cstr(expression)
Window("计算器").WinButton("operator").Click
Window("计算器").WinEdit("Edit").Type cstr(input2)
Window("计算器").WinButton("=").Click
outvalue = cstr(window("计算器").WinEdit("Edit").GetROProperty ("text"))
Window("计算器").WinButton("C").Click
actresult = replace(outvalue,".","")
If trim(cstr(expresult)) <> trim(cstr(actresult)) Then
reporter.ReportEvent 1,"测试结果","失败"
xlsheet.cells(i,7) = "NOK"
xlsheet.cells(i,7).font.color = vbred
else
reporter.ReportEvent 0,"测试结果","成功"
xlsheet.cells(i,7) = "OK"
xlsheet.cells(i,7).font.color = vbgreen
End If
xlSheet.cells(i,6) = actresult
xlSheet.cells(i,6).font.color = vbblue
Next
Window("计算器").Close
xlbook.save
xlApp.DisplayAlerts = False
xlbook.close(true)
xlApp.quit
Set excel=nothing
xls文件内容如下:
caseID input1 expression input2 expresult actresult conclusion
1 4 + 2 6
2 3 - 2 1
3 3 * 5 15
4 6 / 2 20
我的QQ:15736525
[ 本帖最后由 MarsNoNo 于 2007-7-6 17:24 编辑 ] |
|