(一)数据驱动在QTP中的运用--自定义TXT文件
- (一)数据驱动在QTP中的运用--自定义TXT文件......
以下是对Mercury Interactive公司的Flight飞机订票系统的Login模块进行数据驱动测试的VBScript脚本实例,
通过对自定义TXT文件进行读写操作。
Option Explicit
Dim fso
‘数据驱动文件路径,数据文件,当前行
Dim ddFilePath, ddFile, ddCurrLine
‘执行日志文件路径,日志文件
Dim logFilePath, logFile
ddFilePath = Environment.Value("TestDir") & "\ddFile.txt"
logFilePath = Environment.Value("TestDir") & "\logFile.txt"
'====写入测试用例数据到数据驱动文件中===='
Set fso = CreateObject("Scripting.FileSystemObject")
'OpenTextFile第三个参数如果是False表示如果文件一定要存在.
Set ddFile = fso.OpenTextFile(ddFilePath, 2, True)
ddFile.WriteLine "ad,Mercury,Agent name must be at least 4 characters long."
ddFile.WriteLine "admin,merc,Incorrect password. Please try again"
ddFile.WriteLine "admin,Mercury,Flight Reservations"
ddFile.Close
'====写入测试结果到数据日志文件中===='
Set logFile = fso.OpenTextFile(logFilePath, 2, True)
logFile.WriteLine "************************************************************"
logFile.WriteLine "************************************************************"
logFile.WriteLine "*************************测试日志***************************"
logFile.WriteLine "******************用例名称:用户登陆**************************"
logFile.WriteLine "**********************作者:Holly zhao*************************"
logFile.WriteLine "********************执行时间:" & Date & "*********************"
logFile.WriteLine "************************测试开始:**************************"
'从ddFile中读取测试数据
Set ddFile = fso.OpenTextFile(ddFilePath, 1, True)
While NOT ddFile.AtEndOfLine
ddCurrLine = Split(ddFile.ReadLine, ",")
SystemUtil.CloseProcessByName "Flight4a.exe"
SystemUtil.Run Environment.Value("ProductDir") & "\samples\flight\app\flight4a.exe"
Dialog("Login").WinEdit("Agent Name:").Set ddCurrLine(0)
Dialog("Login").WinEdit("Password:").Set ddCurrLine (1)
Dialog("Login").WinButton("OK").Click
If Dialog("Login").Dialog("Flight Reservations").Exist Then
If Dialog("Login").Dialog("Flight Reservations").Static("errInfo").GetROProperty("text") = ddCurrLine(2) Then
logFile.WriteLine "测试成功!"
Else
logFile.WriteLine "测试失败!"
End If
Dialog("Login").Dialog("Flight Reservations").WinButton("确定").Click
Dialog("Login").WinButton("Cancel").Click
Else
If Window("Flight Reservation").Exist Then
logFile.WriteLine "测试成功!"
End If
Window("Flight Reservation").Close
End If
Wend
logFile.WriteLine "====================测试结束========================"
logFile.WriteLine "***************************************************"