QTP软件测试 Windows计算器自动化脚本

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  filename:     QTP_SoftwareTest..vbs
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'  function:     测试Windows自带计算器简单的加减乘除运算
'  run condition: 运行前Object Repository 必须包含对象+-*/,0~9, = Edit(显示结果的文本框)
'  author:    WTU CS0921 dl
'  date:       2012-10-22
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'调用主函数
mainFunc
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'  函数名:     mainFunc
'    功能:     主函数,依次从表格的每一行取出两个数和一个运算符
'         然后计算它们的结果,将测试结果写入到表格test_result
'         然后将test_result和expected_result期望值比较,如果相等]
'         则表示测试通过,否则测试不通过
'     传入参数:   无
'       返回参数    无
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function mainFunc()
 Dim i           '循环变量
 Dim num1            '  从表格中取出的第一个数
 Dim num2         '   从表格中取出的第二个数
 Dim operator      ' 从表格中取出计算两个数的运算符类型
 Dim test_result      '   测试结果
 Dim expected_result   '   预期结果
 Dim tmp         '   临时变量
 
 For i=1 to  DataTable.GetSheet("Action1").getrowcount
   DataTable.GetSheet("Action1").SetCurrentRow(i)
   num1      = cstr(datatable("num1", dtLocalSheet))
   num2     = cstr(datatable("num2", dtLocalSheet))
   operator    = cstr(datatable("operator", dtLocalSheet))
   
   setClick ("CE")
   calcResult num1, num2,  operator
   Window("计算器").WinEdit("Edit").Output CheckPoint("Edit")
   test_result     = RTrim(datatable("test_result", dtLocalSheet)) 'RTrim函数去除字符串后空格
   '如果test_result字符串最后一个字符有小数点,则去除
   If   mid(test_result, len(test_result), 1)= "." Then
    tmp = mid(test_result, 1, len(test_result)-1)
    test_result = mid(tmp, 1, len(tmp))
   End If
   
   expected_result     = (datatable("expected_result", dtLocalSheet))
      If  test_result=expected_result Then
    reporter.ReportEvent  micPass,  "测试通过", "预期值="+expected_result+", " +"实际值="+test_result
   else 
    reporter.ReportEvent   micFail,   "测试失败", "预期值="+expected_result+", " +"实际值="+test_result
   end if
   
 Next
 
End Function
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'  函数名:     calcResult
'    功能:     输入num1和num2后计算结果
'     传入参数:    num1数1  num2数2 operator运算符
'       返回参数    无
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function calcResult(Byval num1, Byval num2, Byval operator)
   inputData(num1)
   setClick(operator)
   inputData(num2)
   setClick("=")
End Function

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'  函数名:     inputData
'    功能:     将data数据输入到计算器中
'     传入参数:    data输入的数据
'       返回参数    无
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function inputData(ByVal data)
   Dim i
 For i=1 to len(data)
  setClick(mid(data, i, 1))
 Next
End Function
 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'  函数名:     setClick
'    功能:     根据点击类型clicktype参数来模拟人
'        单击计算器界面上的按钮
'     传入参数:   click点击的类型
'       返回参数    无
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function setClick(ByVal click)
 Select Case click
   Case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "-", "*", "/", ".", "=", "CE"
                Window("计算器").WinButton(click).Click
 End Select
End function

你可能感兴趣的:(软件工程)