QTP中常用方法.docx

上传人:小飞机 文档编号:3165069 上传时间:2023-03-11 格式:DOCX 页数:9 大小:39.77KB
返回 下载 相关 举报
QTP中常用方法.docx_第1页
第1页 / 共9页
QTP中常用方法.docx_第2页
第2页 / 共9页
QTP中常用方法.docx_第3页
第3页 / 共9页
QTP中常用方法.docx_第4页
第4页 / 共9页
QTP中常用方法.docx_第5页
第5页 / 共9页
亲,该文档总共9页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《QTP中常用方法.docx》由会员分享,可在线阅读,更多相关《QTP中常用方法.docx(9页珍藏版)》请在三一办公上搜索。

1、QTP中常用方法QTP中常用方法 常用方法: Desktop:通过Desktop对象可以访问windows的桌面顶层对象 CaptureBitmap:截图保存到指定文件,如果存在相同文件,可以覆盖 ChildObjects:获取某个测试对象中包含的所有对象 用上面的脚本对flight4b、 flight3a进行回归测试 版本不同时,对象属性值可能不同,导致原脚本不能回放成功,这时可以有如下方法解决: 1 进入对象库直接更改属性值 2 设置TOProperty的值,临时修改属性值 Window(Flight Reservation).WinEdit(Customer Name:).SetTOPr

2、operty attached text,Name: Window(Flight Reservation).WinButton(Insert).SetTOProperty text,&Insert Order“ 3 进入对象库删除属性值不同的对象 因其他属性组合已经能够唯一识别对象,无论text属性怎样变化,都不影响QTP的识别 4 参数化对象属性为DataTable参数 右键对象-选择Objects Property-进行参数化 l 如果忘记了原来录制的脚本的登录密码,你如何解决? Dialog(Login).WinEdit(Agent Name:).Set 1111 Dialog(Logi

3、n).WinEdit(Password:).SetSecure 4cb5c40620a3f4465d6bc6887948127622a968d65d2 截屏方法: l l l l l l l 整个屏幕截屏 desktop.CaptureBitmap D:1.png,True 对某个对象截屏 Dialog(Login).CaptureBitmap D:Dialog.png,False 截屏图片可以是png和bmp格式 Bmp格式文件较大 第二个参数指明是否覆盖原有文件 取字符串方法 l inStr方法:返回某字符串在另一字符串中第一次出现的位置。 l instr (1,查找目标字符串,所查找的字

4、符串) l InStr(start, string1, string2, compare) 这个函数需要的的参数是起始位置、主体字符串、要查找的字符串; l Compare是可选参数。指定字符串比较。 l Compare参数可以是 0, 1或 2。 指定0做二进制比较。指定1做不区分大小写的文本比较。 l 例如我们要查找在字符串“abcdefg”中是否存在“cd”并返回其位置,则使用下面的语句就可以实现: pos=InStr(1,“abcdefg”,“cd”) 则pos会返回3表示查找到并且位置为第三个字符开始。这就是“查找”的实现,而“查找下一个”功能的实现就是把当前位置作为起始位置继续查找

5、。 l 或者:id=87444=ddddd instr(1,id,=),从位置为第一个字符起,查找=字符 mid方法:从字符串中返回指定数量的字符 Mid(string, start, length) l 如:MyVar =Mid(“VB Script is fun!”, 4, 6) MyVar contains “Script” 从第4位字符开始,后面6位字符 l 如:MyVar2=Mid(VB Script is fun,4) MyVar contains Script is fun! 从第4位字符开始,后面的字符 Len :返回字符串长度 l Len(string | varname)

6、l 例子 l Dim MyString MyString = Len(VBSCRIPT) MyString contains 8. Right方法:从字符串中返回指定数量的字符 Right(string, length) 例子: Dim AnyString, MyStr AnyString = Hello World Define string. MyStr = Right(AnyString, 1) Returns d. MyStr = Right(AnyString, 6) Returns World. MyStr = Right(AnyString, 20) Returns Hello

7、World. CInt 函数:返回表达式,此表达式已被转换为 Integer 子类型的 Variant。 l CInt(expression) l expression 参数是任意有效的表达式。 l 下面的示例利用 CInt 函数把值转换为 Integer: l Dim MyDouble, MyInt l MyDouble = 2345.5678 MyDouble 是 Double。 l MyInt = CInt(MyDouble) MyInt 包含 2346。 CStr 函数:返回表达式,该表达式已被转换为 String 子类型的 Variant。 l CStr(expression) l

8、expression 参数是任意有效的表达式。 l 下面的示例利用 CStr 函数把数字转换为 String: l Dim MyDouble, MyString l MyDouble = 437.324 MyDouble 是双精度值。 l MyString = CStr(MyDouble) MyString 包含 437.324。 高亮显示方法:Object.highlight 计算器高亮 Systemutil.Run C:WindowsSystem32calc.exe Set Mydes=Description.Create Mydes(nativeclass).Value=Button F

9、or i=0 to 9 Mydes(text).Value=cstr(i) Mydes(text).Value=i Set Buttonnumber=Window(regexpwndtitle:=计算器,text:=计算器).ChildObjects(Mydes) Buttoncount=Buttonnumber.count Buttonnumber(0).highlight For j=0 to Buttoncount-1 Buttonnumber(j).highlight Next i=i+1 Next 计算器 l 个位数字四则运算,需要对对象做参数化 实例:一位数计算的代码 system

10、util.Run C:WindowsSystem32calc.exe l window(Calculator).WinButton(1).Click l Window(Calculator).WinButton(+).Click l window(Calculator).WinButton(6).Click l Window(Calculator).WinButton(=).Click l Window(Calculator).WinButton(C).Click l Window(Calculator).Close 多位数+一位数的代码 systemutil.Run C:WindowsSys

11、tem32calc.exe Dim num1, butt num1=datatable.Value(num1) For i=1 to len(num1) butt=mid(num1,i,1) Window(计算器).WinButton(butt).Click Next Window(计算器).WinButton(+).Click window(计算器).WinButton(6).Click Window(计算器).WinButton(=).Click Window(计算器).WinButton(C).Click Window(计算器).Close 作业 测试flight订票软件,传真上票价计算

12、是否有误,并将结果写入报告 Window(Flight Reservation).WinObject(Date of Flight:).Type 121212 Window(Flight Reservation).WinComboBox(Fly From:).Select DataTable(from, dtLocalSheet) Window(Flight Reservation).WinComboBox(Fly To:).Select DataTable(to, dtLocalSheet) Window(Flight Reservation).WinButton(FLIGHT).Click

13、 Window(Flight Reservation).Dialog(Flights Table).WinList(From).Select RandomNumber(0, 100) Window(Flight Reservation).Dialog(Flights Table).WinButton(OK).Click Window(Flight Reservation).WinEdit(Name:).Set yiyi Window(Flight Reservation).WinEdit(Tickets:).SetSelection 0,1 Window(Flight Reservation)

14、.WinEdit(Tickets:).Set DataTable(count, dtLocalSheet) Window(Flight Reservation).WinButton(Insert Order).Click Window(Flight Reservation).WinButton(Update Order).Click Window(Flight Reservation).WinEdit(Order No:).Output CheckPoint(Order No:) no=DataTable.GetSheet(3).GetParameter(4) print no Window(

15、Flight Reservation).WinMenu(Menu).Select File;Fax Order. Window(Flight Reservation).Dialog(Fax Order No. 15).SetTOProperty text,Fax Order No. &no Window(Flight Reservation).Dialog(Fax Order No. 15).WinEdit(# Tickets:).Output CheckPoint(# Tickets:) Window(Flight Reservation).Dialog(Fax Order No. 15).

16、WinEdit(Ticket Price:).Output CheckPoint(Ticket Price:) Window(Flight Reservation).Dialog(Fax Order No. 15).WinEdit(Total:).Output CheckPoint(Total:) Window(Flight Reservation).Dialog(Fax Order No. 15).WinObject(Fax Number:).Type 1111111111111 Window(Flight Reservation).Window(Fax Order No. 15).SetT

17、OProperty regexpwndtitle,Fax Order No. &no Window(Flight Reservation).Window(Fax Order No. 15).RunAnalog Track1 Window(Flight Reservation).Dialog(Fax Order No. 15).WinCheckBox(Send Signature with order).Set ON Window(Flight Reservation).Dialog(Fax Order No. 15).WinButton(Send).Click a=DataTable.GetS

18、heet(3).Getparameter(5) b=DataTable.GetSheet(3).Getparameter(6) c=DataTable.GetSheet(3).Getparameter(7) d=a*b c1=Csng(c) d1=Csng(d) print c print d If d=c Then Reporter.ReportEvent micPass,Test Rrsult:,票价计算无误! End If Window(Flight Reservation).WinObject(Fax Sent Successfully).Click 191,15 Window(Fli

19、ght Reservation).WinObject(Fax Sent Successfully).Check CheckPoint(Fax Sent Successfully) 高亮显示计算器上0-9按钮(数据池方式) Dim no no=DataTable.GetSheet(2).GetParameter(1) Window(text:=计算器).Winbutton(text:=&no).click Window(text:=计算器).Winbutton(text:=&no).highlight 高亮显示计算器上任意对象 Dim bu bu=Datatable.GetSheet(2).Ge

20、tParameter(1) Print bu Window(计算器).WinButton(bu).Highlight 测试计算器(多位数加多位数),并将结果写入报告 Window(计算器).Move 460,180 For x=1 to DataTable.GetSheet(2).GetRowCount Dim num,button,num2,button2 num=DataTable.Value(1,2) For m=1 to len(num) button=mid(num,m,1) Window(计算器).WinButton(text:=&button).Click Window(计算器)

21、.WinButton(text:=&button).highlight Next Window(计算器).WinButton(+).Click num2=DataTable.Value(2,2) For n=1 to len(num2) button2=mid(num2,n,1) Window(计算器).WinButton(text:=&button2).Click Window(计算器).WinButton(text:=&button2).highlight Next Window(计算器).WinButton(=).Click Window(计算器).WinEdit(Edit).Outpu

22、t CheckPoint(Edit_2) a=DataTable.GetSheet(2).GetParameter(3) b=DataTable.GetSheet(2).GetParameter(4) c=cint(b) d=cint(a) If d=c Then j=DataTable.GetSheet (2).GetCurrentRow print j If j=1 Then MyY=year(Date) MyM=month(Date) MYD=Day(Date) MYH=Hour(Time) MYMi=Minute(Time) MYS=Second(Time) Set Wordapp =

23、CreateObject(word.application) Set Worddoc=Wordapp.Documents.Add WordDoc.SaveasC:多位加多位测试&MyY&年&MyM&月&MyD&日&MyH&时&MyMi&分&MyS&秒.doc Worddoc.Range.Select Set WordSel=Wordapp.Selection Set oNew= WordSel.Tables.add( WordSel.range,3,2) oNew.Range.Font.Size=8 oNew.cell(1,1).Range.Text=第几组进行测试 oNew.cell(1,2

24、).Range.Text=是否成功 else Set Wordapp =CreateObject(word.application) Set Worddoc= Wordapp.Documents.Open(C:多位加多位测试&MyY&年&MyM&月&MyD&日&MyH&时&MyMi&分&MyS&秒.doc,ForWriting,True) Set oNew = Worddoc.content End If oNew.cell(j+1,1).Range.Text=j oNew.cell(j+1,2).Range.Text=Pass Worddoc.save Worddoc.Close Wordapp.Quit If j2 Then oNew.Rows.add u= oNew.Rows.count oNew.cell(u,2).Range.Text=u-1 oNew.cell(u,2).Range.Text=Pass End If End If Window(计算器).WinButton(C).Click DataTable.GetSheet(2).SetNextRow Next

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号