UFT demo程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 = "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程序的主要内容,如果未能解决你的问题,请参考以下文章

[vscode]--HTML代码片段(基础版,reactvuejquery)

12mmaction2 行为识别商用级别X3D复现 demo实现 检测自己的视频 Expanding Architecturesfor Efficient Video Recognition(代码片段

[异常解决] Keil安装好nRF51822开发环境,运行DEMO报错:Error:“GPIOTE_CONFIG_NUM_OF_LOW_POWER_ENVENTS” is undefined(代码片段

面试常用的代码片段

3-UFT对象管理

uft 测试工具使用