QTP参考代码框架(转)

上一篇 / 下一篇  2009-06-26 17:39:56 / 个人分类:QTP

Dim logdata,sou,ExpectedResult1,ExpectedResult2,ExpectedResult3,ExpectedResult4,ExpectedResult5,ExpectedResult6
sou="F:\work\protocol\bintext\bin\_Debug.log"                                                                                                                              'log文件地址自己填加
'--------------------
Function readlog(sou)
Dim fso,f1,f2
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.OpenTextFile(sou)
f2 = f1.ReadAll
f1.close
readlog=f2
End Function
'-----------------------------------------------------------
Function getdata(x,y)
getdata = CStr(ExcelSheet1.Cells(x, y))
End Function
'---------------------------------------------------------------------------
Function savedata(x,y,z)
ExcelSheet.ActiveSheet.Cells(x,y).Value =z
End Function
'-------------------------------------------------------------
Sub over()
 Set shell = Nothing
Set Shell = Nothing
Set ExcelSheet = Nothing
Set ExcelSheet1 = Nothing
''Excel.Application.Quit
'ExcelSheet.Application.Quit
End Sub
'-----------------------------------------------------------
Dim Excel,ExcelSheet,ExcelSheet1,ExcelSheet2
Set Excel=CreateObject("Excel.Application")
Set ExcelSheet = Excel.Workbooks.Open("F:\work\protocol\qtp\协议测试数据驱动表.xls")        '驱动表格地址自己添加
Set ExcelSheet1= ExcelSheet.Worksheets("测试数据")
ExcelSheet.Application.Visible = True
'------------------------------
Dim oShell,shell,black
SystemUtil.Run "F:\work\protocol\bintext\bin\test.bat","","F:\work\protocol\bintext\bin\" ,"open"  
'测试程序路径和QTP工作路径自己填加修改
Set shell=createobject("Wscript.shell")
'----------------------------------------------------------
'登陆过程
Sub login(userx,usery,pwdx,pwdy,resultx,resulty,savex,savey)  
shell.sendkeys "login:" & getdata(userx,usery) & "," & getdata(pwdx,pwdy) & ",5222 {enter}"
ExpectedResult1 = getdata(resultx,resulty)
logdata = readlog(sou)
If InStr(logdata, ExpectedResult1) Then
call savedata(savex,savey,"PASS")
Else
call savedata(savex,savey,"FAIL")
End If
End Sub
'-------------------------------------------------------------
'   shell.sendkeys 作用是在cmd中输入字符串  如下
'预期结果--可以有任意多的预期结果,变量在顶部填加。
'   getdata(x,y)      用来从表格取数据  x为横向列数  y为纵向列数
'   savedata(x,y)   用来把数据记录到表格中  x为横向列数  y为纵向列数
'检查 --  每次检查预期结果的时候需要从log中取得数据   logdata = readlog(sou)   的作用就是从输入的路径取log数据
'--------------------------------------------------------------------------------------
'函数表
'           login(userx,usery,pwdx,pwdy,resultx,resulty,savex,savey)          userx 表示用户名在excel上的横坐标,usery表示用户名在excel上的纵坐标,依次类推
其他函数过程自己写

 


'-------------------------------------------------------------------------------------

Call login(5,6,5,7,5,12,5,16)    '举例

 


Call over()


TAG:

 

评分:0

我来说两句

Open Toolbar