QTP测试计算器(Cal.exe)例子,经过简单整理及排版,添加注释

Dim fsoInput,fsoOutput,fileInput,readstring,fileOutput,worksheetTmp
Dim one,two
Dim ipos,ilen
isheetrow=1
const forreading=1


set fsoInput=createobject("scripting.filesystemobject")
Set fileInput=fsoInput.opentextfile("E:/Project/QTPTest/TestCal/input.txt",forreading)
Set fsoOutput=createobject("excel.application")
Set fileOutput=fsoOutput.workbooks.open("E:/Project/QTPTest/TestCal/output.xls")
Set worksheetTmp=fileOutput.worksheets("sheet1")

Do while fileInput.atendofline<>true
readstring=fileInput.readline
ipos=instr(1,readstring,",",1)
ilen=len(readstring)
one=left(readstring,ipos-1)
two=right(readstring,ilen-ipos)  
Window("计算器").Activate
Window("计算器").WinButton(one).Click
Window("计算器").WinButton("+").Click
'此次加入catch的结果,(通过OUTPUT,和得到检查的值)
'获取运算符 g=Window("计算器").WinButton("+").GetROProperty("text")
'为期望结果作准备
g1=cdbl(one)+cdbl(two)
Window("计算器").WinButton(two).Click
Window("计算器").WinButton("=").Click
'此处加入判断,比如实际和期望结果比较的条件,来得到是否是失败还是成功 )
'目前只是输出运算值,结果,期望,实际值取法类似
worksheetTmp.cells(isheetrow,1)=g+cstr(isheetrow)
worksheetTmp.cells(isheetrow,2)=one
worksheetTmp.cells(isheetrow,3)=two
worksheetTmp.cells(isheetrow,4)=g1
isheetrow=isheetrow+1
loop
'过程结束!
Window("计算器").Close
'关闭文件流
fileInput.close
'清空文件流数据
fileOutput.close


set fileInput=nothing
set fsoInput=nothing

你可能感兴趣的:(软件测试)