QTPテストのデータ駆動
6786 ワード
テストデータとしてテキストファイルからデータを読み込む
テキストファイルは
2;1;+;1;=0;1;-;1;=1;1;*;1;=1;1;/;1;=
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;=