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

时间: 2024-12-30 23:50:27

UFT demo程序(一)的相关文章

coco2d-js demo程序之滚动的小球

最近有一个游戏叫围住神经猫,报道说是使用html5技术来做的. html5的跨平台的优良特性很不错,对于人手不足,技术不足,选用html5技术实现跨平台的梦想真是不错. 最近在看coco2d-js这个跨平台游戏开发框架,很不错,写了一个demo程序供大家参考. /** * Created by caicai on 14-7-27. */ var Ball = cc.Sprite.extend({ velocity:null, ctor:function () { this._super(res.

RCF进程间通信Demo程序

在上一篇文章RPC通信框架--RCF介绍中,介绍了RCF的优点,本篇文章从头开始演示如何用RCF编写一个跨进程通信的Demo程序. 将RCF编译为静态库 从官网下载到的源码中包含一个RCF的项目,但是这项目是用来编译动态库的.可以参考这个项目来进行静态库的设置. 首先创建一个空的项目文件,然后设置编译为静态库,添加源文件RCF.cpp,只需要这一个文件就够了,因为,这个文件里面,包含了其他所有的源文件.这种源代码的引用方式,编译为动态库,还可以接受,但是编译为静态库就会有一些问题,后面的文章中再

Cocostudio 1.4 实现的Demo程序源代码

开发环境是CocoStudio 1.4 + Cocos2dx 2.2.3 把项目文件放到Cocos2dx下的projects目录下即可运行了 压缩包里面包含了 源代码 和资源文件 1.DemoShop 运行效果 下载地址: 点击打开链接 2.DemoMap 运行效果 下载地址: 点击打开链接 3.ImageViewer 运行效果 下载地址: 点击打开链接 Cocostudio 1.4 实现的Demo程序源代码

ERPSYSTEM开发教程03 DEMO程序开发过程

DEMO程序说明 提供了两个演示接口 IBplOne=interface ['{E4C1C5FA-C598-4834-9111-26B52634068D}'] function Add(A,B:Integer):integer; function Sub(A,B:Integer):Integer; end; IDllOne=interface ['{0434DE04-07C9-4623-9009-CF7892768431}'] function GetString:string; procedu

微信小程序入门——怎么建多个项目?(导入官方Demo程序进行学习)

昨天1月9日微信小程序发布,顿时被朋友圈刷爆,今天看了一下官方文档,自己开始一步一步搭建环境体验小程序开发. 常见问题: 1.微信小程序开发是否需要重新创建开发者账号? 需要,即使之前申请了微信服务号,并认证过,也需要重新申请小程序. 在微信公众平台官网首页(mp.weixin.qq.com)点击右上角的“立即注册”按钮.选择“小程序”,按提示步骤注册即可. 2.个人能否申请小程序? 不能,目前只支持企业.个体工商户.政府.媒体.其他组织. 3.没有资格申请小程序,能否开始小程序开发? 可以,下

WebSocket基于javaweb+tomcat的简易demo程序

由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪费 这种情况下,WebSocket能够解决此问题 它不像普通的http请求或者ajax访问,返回相应的结果就关闭了连接 WebSocket在个人浅薄的知识看来是属于长连接,能保持连接,随时收发数据 所以对WebSocket进行了初步了解,并按照相关的教程尝试做了一个简易demo 首先需要了解的是,W

Lucene入门-安装和运行Demo程序

Lucene是什么 Lucene是一款高性能.可扩展的信息检索工具库.- Lucene In Action Lucene版本:7.1 一.下载安装包 https://lucene.apache.org/core/downloads.html 二.安装 把4个必备jar包和路径添加到CLASSPATH \lucene-7.1.0\core\lucene-core-7.1.0.jar \lucene-7.1.0\queryparser\lucene-queryparser-7.1.0.jar \lu

JavaScript下全选反选的Demo程序里实现checkmeonly函数 DOM

<!doctype html>   <html lang="en">   <head>   <meta charset="UTF-8">   <meta name="Generator" content="EditPlus®">   <meta name="Author" content="">   <meta

PHP MAIL DEMO(程序代码直接发送邮件)

php代码 <?php // 收件人邮箱地址 $to = '[email protected]'; // 邮件主题 $title = '测试邮件发送'; // 邮件内容 $msg = '这是一封测试邮件'; // 发件人邮箱(虚拟的,本身发送的时候并不是用这个邮箱) $from = 'From: [email protected]'; $flag = mail($to, $title, $msg, $from); // 打印结果,如果不加var_dump会有空值转换,即null转成‘’ echo