QTP测试的数据驱动

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

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;=

上一篇:【C 语言】内存四区原理 ( 栈内存与堆内存对比示例 | 函数返回的堆内存指针 | 函数返回的栈内存指针 )


下一篇:探讨:数据驱动型企业与大数据商业模式