自动化测试工具QTP的一些简单代码
2010-07-22 14:29
483 查看
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
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实战技能 5】== QTP中一些基础性代码结构
- 有关开源自动化测试工具--Selenium的一些简单介绍
- 使用EditPlus工具进行简单的C#代码编译和测试
- 【软件自动化测试-QTP实战技能 10】== QTP用到的一些特殊方法
- 自动化测试工具QTP的学习
- 录制简单的自动化测试工具SlikMobile初体验
- 【自动化测试】自动化工具之QTP
- 【自动化测试工具】QTP/UFT入门
- 51IT最全的自动化测试工具QTP资料
- 软件测试_JMeter自动化测试工具2_Jmeter压力测试(简单的http请求)-实例
- 手游公司运维之利用Rundeck自动化运维工具和Shell脚本构建测试环境代码发布平台和生产环境代码发布平台
- 【自动化测试工具】QTP/UFT入门--雷锋
- 常用的一些自动化测试工具列表
- 利用monkey工具进行简单自动化测试
- Windows平台自动化测试工具基于的一些技术简介(笔记)
- 关于TOSCA自动化测试工具, 我想问一些问题(持续整理中)
- 常用的一些性能/自动化工具(lr,jmeter,QTP,)
- web自动化测试工具--Selenium RC的一些学习心得
- 简单介绍--TOSCA自动化测试工具
- 自动化测试工具QTP的使用实例