资源描述:
《数据驱动在QTP中的运用自定义EXCEL文件.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、本节共有两个实例,第一个是把测试用例的数据坷到EXCEL文件屮,第二个是通过读取EXCEL文件中的数据,并把执行结果可入到EXCEL文件中。1.对EXCEL文件进行绪操作OptionExplicitDimfso,ddFilePath,iDimExcelBook,ExcelSheetddFilePath=Environment.Valuef'TestDir")&"ddFile.xls"Setfso=CreateObject("Scripting.FileSystemObject")Iffso.FileExists(ddFilePath)Thenfso.DeleteFile(ddFi
2、lePath)EndIfwait3SetExcelBook=CreateObject("Excel.Application")SetExcelSheet=CreateObject(HExcel.Sheet")ExcelSheet.Application.visible=FalseExcelSheet.ActiveSheet.Cells(1,1).Value="AgentName"ExcelSheet.ActiveSheet.Cells(1,2).Value="Password"ExcelSheet.ActiveSheet.Cells(1,3).Value="ExpireValue"
3、ExcelSheet.ActiveSheet.Cells(1,4).Value=TactValue"ExcelSheet.ActiveSheet.Cells(1,5).Value="ExecuteResult"ExcelSheet.ActiveSheet.Cells(2,1).Value="ad"ExcelSheet.ActiveSheet.Cells(2,2).Value="Mercury"ExcelSheet.ActiveSheet.Cells(2,3).Value="Agentnamemustbeatleast4characterslong."ExcelSheet.Activ
4、eSheet.Cells(3,1).Value="Admin"ExcelSheet.ActiveSheet.Cells(3,2).Value="Merc"ExcelSheet.ActiveSheet.Cells(3,3).Value="Incorrectpassword.Pleasetryagain1'ExcelSheet.ActiveSheet.Cells(4,1).Value="Admin"ExcelSheet.ActiveSheet.Cells(4,2).Value="Mercury"ExcelSheet.ActiveSheet.Cells(4,3).Value="Fligh
5、tReservation"ExcelSheet.SaveAsddFilePathExcelBook.QuitSetExcelBook=Nothing2.对EXCEL文件进行读写操作OptionExplicitDimfso,filePath,iDimExcelBook,ExcelSheet,myExcelBook,myExcelSheetfilePath=Environment.Value("TestDir")&"ddFile.xls"Setfso=CreateObject(”Scripting.FileSystemObject”)SetExcelBook=CreateObject
6、(HExcel.Application”)SetExcelSheet=CreateObject(HExcel.Sheet")SetmyExcelBook=ExcelBook.WorkBooks.Open(filePath)SetmyExcelSheet=myExcelBook.WorkSheets(nSheet1")Fori=2To4Systemlltil.CloseProcessByNameTlight4a.exe"SystemUtil.RunEnvironment.Value(MProductDirH)&Hsamplesflightappflight4a.exe"Dia
7、log("Login").WinEdit("AgentName:").SetmyExcelSheet.Cells(iJ1)Dialog(”Login”).WinEdit(”Password:”).SetmyExcelSheet.Cells(i,2)Dialog(”LogirT).WinButton(”OK”).CIickIfDialog(”Login”).Dialog(”FlightReservations").ExistThenmyExcelSheet.Cells(