1. 程式人生 > >UFT demo程序(一)

UFT demo程序(一)

nal dem *** wine tex 原因 clas 成功 讀取excel

此程序使用dp方式,調用外部函數,最終結果入Excel

 1 Option explicit
 2 systemutil.Run "C:\Program Files (x86)\HP\Unified Functional Testing\samples\flight\app\flight4b"
 3 ExecuteFile "C:\Auto-Flight\object.vbs"
 4 ExecuteFile "C:\Auto-Flight\function.vbs"
 5 Dim WarnStaticLogin,WarnStaticPassword,CheckValue,HopeValue,ActualValue
6 7 錯誤的用戶名,正確的密碼 8 With Dialog(MyDialog) 9 .WinEdit(MyName).Set ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",4,5) 10 .WinEdit(MyPwd).Set ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",4,6) 11 .WinButton(MyButton).Click 12 End With 13 WarnStaticLogin = Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).Static(WarnStatic_login).GetROProperty("
regexpwndtitle") 14 If WarnStaticLogin = "Agent name must be at least 4 characters long." Then 15 CheckValue = "Agent name must be at least 4 characters long." 16 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",4,8) 17 HopeValue = ReadExcel("C:\Auto-Flight\testCases.xls","TestCases
",4,7) 18 ActualValue = ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",4,8) 19 If HopeValue = ActualValue Then 20 CheckValue = "Pass" 21 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",4,9) 22 else 23 CheckValue = "Fail" 24 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",4,9) 25 End If 26 Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).WinButton(ConfirmButton).Click 27 else 28 ExitTest 29 End If 30 31 正確的用戶名,錯誤的密碼 32 wait 5 33 With Dialog(MyDialog) 34 .WinEdit(MyName).Set ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",5,5) 35 .WinEdit(MyPwd).Set ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",5,6) 36 .WinButton(MyButton).Click 37 End With 38 WarnStaticPassword = Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).Static(WarnStatic_password).GetROProperty("regexpwndtitle") 39 If WarnStaticPassword = "Password must be at least 4 characters long" Then 40 CheckValue = "Password must be at least 4 characters long" 41 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",5,8) 42 HopeValue = ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",5,7) 43 ActualValue = ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",5,8) 44 If HopeValue = ActualValue Then 45 CheckValue = "Pass" 46 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",5,9) 47 else 48 CheckValue = "Fail" 49 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",5,9) 50 End If 51 Dialog(MyDialog).Dialog(Flight_Reservations_Dialog).WinButton(ConfirmButton).Click 52 else 53 ExitTest 54 End If 55 56 57 正確的用戶名、密碼 58 wait 5 59 With Dialog(MyDialog) 60 .WinEdit(MyName).Set ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",3,5) 61 .WinEdit(MyPwd).Set ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",3,6) 62 .WinButton(HelpButton).Click 63 .Dialog(Flight_Reservations_Dialog).WinButton(ConfirmButton).Click 64 .WinButton(MyButton).Click 65 End With 66 If Window(MyWindow).Exist(5) Then 67 CheckValue = "成功登錄" 68 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",3,8) 69 HopeValue = ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",3,7) 70 ActualValue = ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",3,8) 71 If HopeValue = ActualValue Then 72 CheckValue = "Pass" 73 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",3,9) 74 else 75 CheckValue = "Fail" 76 Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",3,9) 77 End if 78 Window(MyWindow).WinMenu(MyMenu).Select "File;Exit" 79 else 80 ExitTest 81 End If

調用聲明函數object

 1 Option Explicit
 2 Dim MyDialog,MyName,MyPwd,MyButton,MyWindow,MyMenu,Flight_Reservations_Dialog,WarnStatic_login,WarnStatic_password,ConfirmButton,CancelButton,HelpButton
 3 Set MyDialog = Description.Create()
 4         MyDialog("text").value="Login"
 5 Set MyName = Description.Create()
 6         MyName("nativeclass").value = "Edit"
 7         MyName("attached text").value = "Agent Name:"
 8 Set MyPwd = Description.Create()
 9         MyPwd("nativeclass").value = "Edit"
10         MyPwd("attached text").value= "Password:"
11 Set MyButton = Description.Create()
12         MyButton("text").value = "OK"
13         MyButton("nativeclass").value="Button"
14 Set MyWindow = Description.Create()
15         MyWindow("regexpwndtitle").value = "Flight Reservation"
16 Set MyMenu = Description.Create()
17         MyMenu("menuobjtype").value = "2"
18 Set Flight_Reservations_Dialog = Description.Create()
19         Flight_Reservations_Dialog("text").value = "Flight Reservations"
20         Flight_Reservations_Dialog("regexpwndtitle").value = "Flight Reservations"
21 Set WarnStatic_login = Description.Create()
22         WarnStatic_login("nativeclass").value = "Static"
23         WarnStatic_login("text").value = "Agent name must be at least 4 characters long."
24 Set WarnStatic_password = Description.Create()
25         WarnStatic_password("nativeclass").value = "Static"
26         WarnStatic_password("text").value = "Password must be at least 4 characters long"
27 Set CancelButton = Description.Create()
28         CancelButton("regexpwndtitle").value = "Cancel"
29 Set ConfirmButton = Description.Create()
30         ConfirmButton("regexpwndtitle").value = "確定"
31 Set HelpButton = Description.Create()
32         HelpButton("regexpwndtitle").value = "Help"

調用方法function

***********************定義讀取excel函數函數:ReadExcel函數作用:操作Excel(讀)修改時間:修改原因:修改者:hx***********************
Function ReadExcel(filepath,sheetname,x,y)
   Dim ObjExcel,SrcExcel,ExcValue
   Set ObjExcel = CreateObject("Excel.Application")
   ObjExcel.Visible = false
   Set SrcExcel = ObjExcel.Workbooks.Open(filepath)
   SrcExcel.Worksheets(sheetname).Activate
   ExcValue = SrcExcel.Worksheets(sheetname).Cells(x,y).Value
   ReadExcel = ExcValue
   ObjExcel.DisplayAlerts = false
   ObjExcel.Save
   ObjExcel.Quit
   Set ObjExcel = nothing
   Set SrcExcel = nothing
End Function
***********************定義讀取excel函數函數:WriteExcel函數作用:操作Excel(寫)修改時間:修改原因:修改者:hx***********************
Function DoExcel(filepath,sheetname,x,y)
   Dim ObjExcel,SrcExcel
   Set ObjExcel = CreateObject("Excel.Application")
   ObjExcel.Visible = false
   Set SrcExcel = ObjExcel.Workbooks.Open(filepath)
   SrcExcel.Worksheets(sheetname).Activate
   SrcExcel.Worksheets(sheetname).Cells(x,y).Value = CheckValue
   ObjExcel.DisplayAlerts = false
   ObjExcel.Save
   ObjExcel.Quit
   Set ObjExcel = nothing
   Set SrcExcel = nothing
End Function

結果進入Excel,判斷pass 或者 fail

UFT demo程序(一)