首页 > 代码库 > UFT demo程序(一)

UFT demo程序(一)

此程序使用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 = http://www.mamicode.com/"Agent name must be at least 4 characters long."
16     Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",4,8)
17     HopeValue = http://www.mamicode.com/ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",4,7)
18     ActualValue = http://www.mamicode.com/ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",4,8)
19     If HopeValue =http://www.mamicode.com/ ActualValue Then
20         CheckValue = http://www.mamicode.com/"Pass"
21             Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",4,9)
22         else 
23             CheckValue = http://www.mamicode.com/"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 = http://www.mamicode.com/"Password must be at least 4 characters long"
41     Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",5,8)
42     HopeValue = http://www.mamicode.com/ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",5,7)
43     ActualValue = http://www.mamicode.com/ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",5,8)
44     If HopeValue =http://www.mamicode.com/ ActualValue Then
45         CheckValue = http://www.mamicode.com/"Pass"
46             Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",5,9)
47         else
48             CheckValue = http://www.mamicode.com/"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 = http://www.mamicode.com/"成功登录"
68     Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",3,8)
69     HopeValue = http://www.mamicode.com/ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",3,7)
70     ActualValue = http://www.mamicode.com/ReadExcel("C:\Auto-Flight\testCases.xls","TestCases",3,8)
71     If HopeValue =http://www.mamicode.com/ ActualValue Then
72         CheckValue = http://www.mamicode.com/"Pass"
73             Call DoExcel ("C:\Auto-Flight\testCases.xls","TestCases",3,9)
74         else
75             CheckValue = http://www.mamicode.com/"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=http://www.mamicode.com/"Login"
 5 Set MyName = Description.Create()
 6         MyName("nativeclass").value = http://www.mamicode.com/"Edit"
 7         MyName("attached text").value = http://www.mamicode.com/"Agent Name:"
 8 Set MyPwd = Description.Create()
 9         MyPwd("nativeclass").value = http://www.mamicode.com/"Edit"
10         MyPwd("attached text").value= http://www.mamicode.com/"Password:"
11 Set MyButton = Description.Create()
12         MyButton("text").value = http://www.mamicode.com/"OK"
13         MyButton("nativeclass").value=http://www.mamicode.com/"Button"
14 Set MyWindow = Description.Create()
15         MyWindow("regexpwndtitle").value = http://www.mamicode.com/"Flight Reservation"
16 Set MyMenu = Description.Create()
17         MyMenu("menuobjtype").value = http://www.mamicode.com/"2"
18 Set Flight_Reservations_Dialog = Description.Create()
19         Flight_Reservations_Dialog("text").value = http://www.mamicode.com/"Flight Reservations"
20         Flight_Reservations_Dialog("regexpwndtitle").value = http://www.mamicode.com/"Flight Reservations"
21 Set WarnStatic_login = Description.Create()
22         WarnStatic_login("nativeclass").value = http://www.mamicode.com/"Static"
23         WarnStatic_login("text").value = http://www.mamicode.com/"Agent name must be at least 4 characters long."
24 Set WarnStatic_password = Description.Create()
25         WarnStatic_password("nativeclass").value = http://www.mamicode.com/"Static"
26         WarnStatic_password("text").value = http://www.mamicode.com/"Password must be at least 4 characters long"
27 Set CancelButton = Description.Create()
28         CancelButton("regexpwndtitle").value = http://www.mamicode.com/"Cancel"
29 Set ConfirmButton = Description.Create()
30         ConfirmButton("regexpwndtitle").value = http://www.mamicode.com/"确定"
31 Set HelpButton = Description.Create()
32         HelpButton("regexpwndtitle").value = http://www.mamicode.com/"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程序(一)