孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

从文本文件读取数据作为测试的数据

Dim oShell
Set oShell=CreateObject("WSCript.shell")
oShell.Run "calc",1
Wait 2

'Window("计算器").WinButton("1").Click
'Window("计算器").WinButton("+").Click
'Window("计算器").WinButton("1").Click
'Window("计算器").WinButton("=").Click
'Window("计算器").WinEdit("Edit").Check CheckPoint("Edit_2")
'Window("计算器").Close
Set F=OpenFile("Calc.txt",1)
Do While F.AtEndOfLine <> True
    btn_str=F.ReadLine
    btn_array=Split(btn_str,";")
    Expected=btn_array(0)
    ExecuteTest(btn_array(1))
    ExecuteTest(btn_array(1))
    ExecuteTest(btn_array(1))
    ExecuteTest(btn_array(1))
    Verify(Expected)
Loop
CloseFile(F)

Function OpenFile(FilePath,mode)
   Dim oFSO
    Set oFSO=CreateObject("Scripting.FileSystemObject")
   set OpenFile=oFSO.OpenTextFile(FilePath,mode,True)
End Function

Function CloseFile(byref FileRef)
   FileRef.close
End Function

Function ExecuteTest(Operator)
    Select Case Operator
        Case "0"
            Window("计算器").WinButton("0").Click
        Case "1"
            Window("计算器").WinButton("1").Click
        Case "2"
            Window("计算器").WinButton("2").Click
        Case "3"
            Window("计算器").WinButton("3").Click
         Case "4"
            Window("计算器").WinButton("4").Click
        Case "5"
            Window("计算器").WinButton("5").Click
        Case "6"
            Window("计算器").WinButton("6").Click
        Case "7"
            Window("计算器").WinButton("7").Click
        Case "8"
            Window("计算器").WinButton("8").Click
        Case "9"
            Window("计算器").WinButton("9").Click

          Case "+"
            Window("计算器").WinButton("+").Click
        Case "-"
            Window("计算器").WinButton("-").Click
        Case "*"
            Window("计算器").WinButton("*").Click
        Case "/"
            Window("计算器").WinButton("/").Click
    End Select
Window("计算器").WinButton("=").Click
End Function

Function Verify(expected)
   actual=Window("计算器").WinEdit("Edit").GetROProperty("text")
   If Cint(actual)=Cint(expected) Then
       Reporter.ReportEvent micPass,"",""
    else
        Reporter.ReportEvent mcifail,"",""
   End If
End Function

文本文件为

2;1;+;1;=
0;1;-;1;=
1;1;*;1;=
1;1;/;1;=

posted on 2013-05-01 19:11  孤独的猫  阅读(470)  评论(0编辑  收藏  举报