|
'#############程序说明开始###########################
'被测对象:windows自带的计算器
'功能:
'1.随机产生数
'2.生成日志文件
'作者:小强
'更多视频作品请关注www.boobooke.com/bbs,小强作品
'多多在线看视频,适量点击视频左侧广告就是对我们的支持
'我的blog:http://blog.sina.com.cn/xqtesting
'############程序说明结束##################################
Option Explicit '强制声明变量
Environment.Value("RunTimes") =3' 执行测试次数
'主函数'开始
'让QTP运行时保持最小化
Dim objQTPWin
Set objQTPWin = GetObject("" , "QuickTest.Application")
objQTPWin.WindowState = "Minimized"
'获取当前日期和时间
Dim currentTime,currentDate
currentDate = Date
currentTime = Time
'写入测试报告
Dim fileSystemObj,fileSpec,logFile
Set fileSystemObj = CreateObject("Scripting.FileSystemObject")
fileSpec ="C:\" &"计算器测试报告-小强"& ".txt"
Set logFile = fileSystemObj.OpenTextFile(fileSpec, 8, true)
logFile.WriteLine ("##############################################")
logFile.WriteLine ("######被测对象:windows自带的计算器#########")
logFile.WriteLine ("######作者:小强 blog:http://blog.sina.com.cn/xqtesting ########")
logFile.WriteLine ("##### 测试日期:" + cstr(currentDate) + cstr(currentTime) + " ####")
logFile.WriteLine("#####更多小强作品:www.boobooke.com/bbs ########")
logFile.WriteLine ("##############################################")
logFile.WriteLine ("")
Dim i,op1,op2,operator
For i =1 to Environment.Value("RunTimes") '要循环的次数
SystemUtil.Run "C:\WINDOWS\system32\calc.exe","","","open"
Set op1=description.Create()
Set op2=description.Create()
op1("text").value=randomnumber(0,9)
op2("text").value=randomnumber(0,9)
Window("计算器").Activate
Window("计算器").WinButton(op1).Click
Window("计算器").Activate
operator = GetOperation()
Window("计算器").Activate
Window("计算器").WinButton(op2).Click
Window("计算器").Activate
Window("计算器").WinButton("=").Click
'获取实际结果
Dim RealValue
RealValue = Window("计算器").WinEdit("Edit").GetROProperty("text")
Dim express '测试表达式
Select Case operator
Case 0 express = cstr(op1("text").value) + "+" + cstr(op2("text").value) + "= ?"
Case 1 express = cstr(op1("text").value) + "-" + cstr(op2("text").value) + "= ?"
Case 2 express = cstr(op1("text").value) + "*" + cstr(op2("text").value) + "= ?"
Case 3 express = cstr(op1("text").value) + "/" + cstr(op2("text").value) + "= ?"
End Select
logFile.WriteLine ("测试表达式:" + express)
logFile.WriteLine ("计算结果为:" + trim(cstr(RealValue)))
logFile.WriteLine ("" )
Window("计算器").Close
Next
'关闭文件
logFile.Close
Set logFile = Nothing
'恢复QTP窗口
objQTPWin.WindowState = "Restored"
Set objQTPWin = Nothing
'随机生成操作符
Function GetOperation()
Dim oper
oper =randomnumber.Value(0,3)
Window("计算器").Activate
Select Case oper
Case 0 Window("计算器").WinButton("+").Click
Case 1 Window("计算器").WinButton("-").Click
Case 2 Window("计算器").WinButton("*").Click
Case 3 Window("计算器").WinButton("/").Click
Case Else
End Select
GetOperation = oper
End Function |
|