TA的每日心情 | 奋斗 2021-8-16 14:04 |
---|
签到天数: 1 天 连续签到: 1 天 [LV.1]测试小兵
|
利用自动化框架对demo进行修改,框架分为6个部分,分别为commonlib,testcase,testlog,testo
bject,testpic,testscript
commonlib存放自定义函数
testcase存放测试用例
testlog存在测试日志
testobject存放对象库
testpic存放错误截图
testscript存放测试脚本
目的在于把测试脚本分拆,用函数封装主要功能,框架总体积缩小,方便自动化测试,脚本如下:
外部运行脚本启动UFT,自动执行用例:
- 1 Dim qtapp
- 2 Set qtapp=CreateObject("quicktest.application")
- 3 qtapp.Launch
- 4 qtapp.Visible=True
- 5 qtapp.Open "C:\AutoTest\testscript\Flight-Demo"
- 6 qtapp.Test.Run
- 7 qtapp.Quit
- 8 Set qtapp = nothing
- 复制代码
- 控制脚本,脚本主体框架:
- 复制代码
- 1 Option explicit
- 2 '1、目录生成
- 3 Dim testpath,testpaths
- 4 testpath = Environment.Value("TestDir")
- 5 testpaths = split(testpath,"testscript")
- 6 ExecuteFile testpaths(0)&"commonlib\createfolder.vbs"
- 7 createfolder testpaths(0)&"testlog"
- 8 createfolder testpaths(0)&"testpic"
- 9
- 10 '2、测试用例加载
- 11 '判断测试用例是否存在
- 12 ExecuteFile testpaths(0)&"commonlib\loadcase.vbs"
- 13 loadcase testpaths(0)&"testcase\testCases.xls","Login"
- 14
- 15 '3、生成日志
- 16 ExecuteFile testpaths(0)&"commonlib\logPrint.vbs"
- 17 ExecuteFile testpaths(0)&"commonlib\ErrHandle.vbs"
- 18
- 19 '4、应用程序启动
- 20 logPrint("开始进入功能:flight登陆功能")
- 21 ExecuteFile testpaths(0)&"commonlib\OpenApp.vbs"
- 22 OpenApp "flight4b.exe","C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4b",""
- 23
- 24 '5、测试对象加载(如果有对象库,则通过loadtsr方法加载)
- 25 ExecuteFile testpaths(0)&"commonlib\loadtsr.vbs"
- 26 ExecuteFile testpaths(0)&"testscript\login.vbs"
- 复制代码
- 测试脚本主体:
- 复制代码
- 1 Dim WarnStaticLogin,WarnStaticPassword,CheckValue,ExpectValue,ActualValue
- 2 ExecuteFile testpaths(0)&"commonlib\object.vbs"
- 3 ExecuteFile testpaths(0)&"commonlib\function.vbs"
- 4
- 5
- 6 logPrint("执行登陆条件:错误的用户名,正确的密码")
- 7 With Dialog(MyDialog)
- 8 .WinEdit(MyName).Set ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",4,5)
- 9 .WinEdit(MyPwd).Set ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",4,6)
- 10 .WinButton(MyButton).Click
- 11 End With
- 12 WarnStaticLogin = Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).Static(WarnStatic_login).GetROProperty("regexpwndtitle")
- 13 If WarnStaticLogin = "Agent name must be at least 4 characters long." Then
- 14 CheckValue = "Agent name must be at least 4 characters long."
- 15 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",4,8)
- 16 ExpectValue = ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",4,7)
- 17 ActualValue = ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",4,8)
- 18 If ExpectValue = ActualValue Then
- 19 CheckValue = "Pass"
- 20 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",4,9)
- 21 else
- 22 CheckValue = "Fail"
- 23 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",4,9)
- 24 End If
- 25 Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).WinButton(ConfirmButton).Click
- 26
- 27 ExitTest
- 28 End If
- 29
- 30 logPrint("执行登陆条件:正确的用户名,错误的密码")
- 31 wait 5
- 32 With Dialog(MyDialog)
- 33 .WinEdit(MyName).Set ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",5,5)
- 34 .WinEdit(MyPwd).Set ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",5,6)
- 35 .WinButton(MyButton).Click
- 36 End With
- 37 WarnStaticPassword = Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).Static(WarnStatic_password).GetROProperty("regexpwndtitle")
- 38 If WarnStaticPassword = "Password must be at least 4 characters long" Then
- 39 CheckValue = "Password must be at least 4 characters long"
- 40 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",5,8)
- 41 ExpectValue = ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",5,7)
- 42 ActualValue = ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",5,8)
- 43 If ExpectValue = ActualValue Then
- 44 CheckValue = "Pass"
- 45 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",5,9)
- 46 else
- 47 CheckValue = "Fail"
- 48 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",5,9)
- 49 End If
- 50 Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).WinButton(ConfirmButton).Click
- 51 else
- 52 ExitTest
- 53 End If
- 54
- 55
- 56 logPrint("执行登陆条件:正确的用户名、密码")
- 57 wait 5
- 58 With Dialog(MyDialog)
- 59 .WinEdit(MyName).Set ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",3,5)
- 60 .WinEdit(MyPwd).Set ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",3,6)
- 61 .WinButton(HelpButton).Click
- 62 .Dialog(Flight_Reservations_Dialog).WinButton(ConfirmButton).Click
- 63 .WinButton(MyButton).Click
- 64 End With
- 65 If Window(MyWindow).Exist(5) Then
- 66 CheckValue = "成功登录"
- 67 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",3,8)
- 68 ExpectValue = ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",3,7)
- 69 ActualValue = ReadExcel(testpaths(0)&"testcase\testCases.xls","Login",3,8)
- 70 If ExpectValue = ActualValue Then
- 71 CheckValue = "Pass"
- 72 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",3,9)
- 73 else
- 74 CheckValue = "Fail"
- 75 Call DoExcel (testpaths(0)&"testcase\testCases.xls","Login",3,9)
- 76 End if
- 77 Window(MyWindow).WinMenu(MyMenu).Select "File;Exit"
- 78 else
- 79 ExitTest
- 80 End If
- 81 logPrint("登陆用例执行完毕")
- 复制代码
- createfolder.vbs创建文件夹:
- 复制代码
- 1 Option Explicit
- 2 Sub createfolder(folderpath)
- 3 Dim fso,f
- 4 Dim blfolderexist
- 5 Set fso = CreateObject("scripting.filesystemobject")
- 6 blfolderexist = fso.FolderExists(folderpath)
- 7 If blfolderexist Then
- 8 MsgBox folderpath&"已存在"
- 9 fso.DeleteFolder(folderpath)
- 10 End If
- 11 Set f = fso.CreateFolder(folderpath)
- 12 Set fso = Nothing
- 13 End Sub
- 复制代码
- ErrHandle.vbs日志:
- 复制代码
- 1 Public Function ErrHandle()
- 2 If Err.Number <> 0 Then
- 3 logPrint "Error Num: " & Err.Number & "; Error Src: " & Err.Source & "; Error Desc: " & Err.Description
- 4 Err.Clear
- 5 End If
- 6 End Function
- 复制代码
- loadcase.vbs确定测试用例的存在:
- 复制代码
- 1 Sub loadcase(casepath,casename)
- 2 Dim fso,blcaseexist
- 3 Set fso = CreateObject("scripting.filesystemobject")
- 4 blcaseexist = fso.FileExists(testpaths(0)&"testcase\testCases.xls")
- 5 If blcaseexist Then
- 6 DataTable.ImportSheet casepath,"Login","login"
- 7 Else
- 8 Reporter.ReportEvent micFail,"Login Test","测试用例不存在"
- 9 ExitTest
- 10 End If
- 11 Set fso = nothing
- 12 End Sub
- 复制代码
- loadtsr.vbs调用对象库:
- 1 Sub loadtsr(tsrname)
- 2 RepositoriesCollection.RemoveAll
- 3 RepositoriesCollection.Add tsrname
- 4 End Sub
- logPrint.vbs日志:
- 复制代码
- 1 Public Function logPrint(ByVal logMessage)
- 2 Dim fso,logFile
- 3 Set fso=CreateObject("scripting.filesystemobject")
- 4 Set logFile = fso.OpenTextFile(testpaths(0)&"testlog\runtime.log",8,true)
- 5 logFile.WriteLine(date() & " " & hour(now) & ":" & minute(now) & ":" & second(now) & ": " & logMessage)
- 6 logFile.Close
- 7 End Function
- 复制代码
- OpenApp.vbs打开应用程序,之所以不用systemutil.Run,是为了方便把已打开的程序关闭:
复制代码
|
|