自动化测试工具QTP的一些简单代码
来源:互联网 发布:拨号钢琴软件 编辑:程序博客网 时间:2024/05/27 20:12
1,利用QTP向excel表格中写入数据:
Option explicit
Dim fso,ddfile
Dim excelbook,excelsheet
ddfile="F:/test/data.xls"
Set fso=createobject("scripting.filesystemobject")
If fso.fileexists(ddfile) Then
fso.deletefile(ddfile)
End If
wait 3
Set excelbook=createobject("excel.application")
Set excelsheet=createobject("excel.sheet")
excelsheet.application.visible=false
ExcelSheet.ActiveSheet.Cells(1,1).Value = "Agent Name"
ExcelSheet.ActiveSheet.Cells(1,2).Value = "Password"
ExcelSheet.ActiveSheet.Cells(1,3).Value = "Expire Value"
ExcelSheet.ActiveSheet.Cells(1,4).Value = "Fact Value"
ExcelSheet.ActiveSheet.Cells(1,5).Value = "Execute Result"
ExcelSheet.ActiveSheet.Cells(2,1).Value = "ad"
ExcelSheet.ActiveSheet.Cells(2,2).Value = "Mercury/"
ExcelSheet.ActiveSheet.Cells(2,3).Value = "Agent name must be at least 4 characters long."
ExcelSheet.ActiveSheet.Cells(3,1).Value = "Admin"
ExcelSheet.ActiveSheet.Cells(3,2).Value = "Merc"
ExcelSheet.ActiveSheet.Cells(3,3).Value = "Incorrect password. Please try again"
ExcelSheet.ActiveSheet.Cells(4,1).Value = "Admin"
ExcelSheet.ActiveSheet.Cells(4,2).Value = "Mercury"
ExcelSheet.ActiveSheet.Cells(4,3).Value = "Flight Reservation"
excelsheet.saveas ddfile
excelbook.quit
set excelbook=nothing
2,利用QTP向excel表格中读写数据:
Option explicit
Dim fso,filepath,i
Dim excelbook,excelsheet,myexcelbook,myexcelsheet
filepath="F:/test/data.xls"
Set fso=createobject("scripting.filesystemobject")
Set excelbook=createobject("excel.application")
Set excelsheet=createobject("excel.sheet")
Set myexcelbook=excelbook.workbooks.open(filepath)
Set myexcelsheet=myexcelbook.worksheets("sheet1")
For i=2 to 4
systemutil.CloseProcessByName "Flight4a.exe"
systemutil.Run "C:/Program Files/Mercury Interactive/QuickTest Professional/samples/flight/app/flight4a.exe"
dialog("Login").WinEdit("Agent Name:").Set myexcelsheet.cells(i,1)
dialog("Login").WinEdit("Password:").Set myexcelsheet.cells(i,2)
dialog("Login").WinButton("OK").Click
If dialog("Login").Dialog("Flight Reservations").Exist Then
myexcelsheet.cells(i,4).value=dialog("Login").Dialog("Flight Reservations").static("errInfo").GetROProperty("text")
If dialog("Login").Dialog("Flight Reservations").static("errInfo").GetROProperty("text")=myexcelsheet.cells(i,3) Then
myexcelsheet.cells(i,5).font.color=vbblue
myexcelsheet.cells(i,5).value="pass"
else
myexcelsheet.cells(i,5).font.color=vbred
myexcelsheet.cells(i,5).value="false"
End If
dialog("Login").Dialog("Flight Reservations").winbutton("确定").Click
dialog("Login").WinButton("Cancel").Click
elseif window("Flight Reservation").Exist then
myexcelsheet.cells(i,4).value=window("Flight Reservation").GetROProperty("text")
myexcelsheet.cells(i,5).font.color=vbblue
myexcelsheet.cells(i,5).value="pass"
window("Flight Reservation").Close
else
logfile.writeline "no window,false!"
exitaction
End If
Next
myexcelbook.save
excelbook.quit
Set excelbook=nothing
3,从txt文件中读出数据执行用例:
Dim fso
Dim f
systemutil.Run "F:/test/calc.exe"
Set fso=createobject("scripting.filesystemobject")
Set f=fso.opentextfile("F:/test/date.txt",1,false)
Do while f.atendofline <> true
strtemp=f.readline
x=split(strtemp,",")
For i=1to len(x(0))
btn=mid(x(0),i,1)
window("计算器").WinButton(btn).Click
Next
btn=x(2)
window("计算器").WinButton(btn).Click
For i=1 to len(x(1))
btn=mid(x(1),i,1)
window("计算器").WinButton(btn).Click
Next
btn="="
window("计算器").WinButton(btn).Click
a=window("计算器").WinEdit("Edit").GetROProperty("text")
msgbox a
Loop
window("计算器").Close
f.close
Set f=nothing
Set fso=nothing
- 自动化测试工具QTP的一些简单代码
- QTP自动化测试工具的介绍
- 自动化测试工具QTP的使用实例
- 自动化测试工具QTP的学习
- 认识QTP自动化测试工具
- 《QTP自动化测试实践》读者来信 - 买《QTP自动化测试实践》后的一些看法
- 【软件自动化测试-QTP实战技能 5】== QTP中一些基础性代码结构
- 常用的一些性能/自动化工具(lr,jmeter,QTP,)
- 51IT最全的自动化测试工具QTP资料
- 最全的自动化测试工具QTP资料
- Mercury自动化功能测试工具QTP下载
- 自动化测试工具介绍QTP篇
- 【自动化测试工具】QTP/UFT入门
- 【自动化测试工具】QTP/UFT入门
- 【自动化测试工具】QTP/UFT入门--雷锋
- 【软件自动化测试-QTP实战技能 10】== QTP用到的一些特殊方法
- 常用的一些自动化测试工具列表
- 常用的一些自动化测试工具列表
- 单向链表反转
- SQL小应用
- 一个最简单的SQL SERVER 触发器
- 数据库的索引
- How to reset the Verity K2 password.
- 自动化测试工具QTP的一些简单代码
- spring2.5注解介绍之一
- 颜色基础知识
- spring2.5注解介绍之二
- ext实现遮罩效果
- 三十分钟掌握STL
- 报表软件选购指南
- 长字符串数字相乘
- 一个简单的编辑器