1、在测试中我们使用QTP调试脚本的时候一般就是DEBUG或者MSGBOX察看一些信息,其实有时候也可以使用print来实现批量的察看信息但是不影响程序运行:
a="100"
print a
2、取datatable特定行的数据可以这样使用:
DataTable.GetSheet("Action1").GetParameter("test").ValueByRow(4)
3、Wait Seconds [, Milliseconds]可以精确到毫秒
4、在自定义的function里面数组作为返回值:
circuit = "399937"
Function trimString(circuit)
Dim holdArray(5)
holdArray(0) = Left(circuit, 2)
holdArray(1) = Right(circuit, 2)
msgbox holdArray(0) 'showed 39
trimString = holdArray' I get an out of range error here
End Function
dim myArray
'here I want to assign the return array to another array
myArray = trimString(circuit)
' and then call one element from it
msgbox myArray(1)
5、计算一个操作的时间:
Browser("Browser").Page("Page").Image("getRates").Click
var_StartTime = Timer
Browser("Browser").Page("Page").Sync
Browser("Browser").Page("Page").Check CheckPoint("Check1")
var_EndTime = Timer
intRespTime = round ((var_EndTime - var_StartTime), 2 )
msgbox (intRespTime)
6、取得指定sheet(datatable)的行数和列数(也可以理解为参数个数):
paramcount = DataTable.GetSheet("Action1").GetParameterCount
msgbox "There are " ¶mcount&"columns in the data sheet."
rowcount = DataTable.GetSheet("Action1").GetRowCount
msgbox "There are " &rowcount&"rows in the data sheet."
7、一种设置全局变量的方法GlobalDictionary:
A、
Dim WshShell
Set WshShell =CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Software\Mercury Interactive\QuickTest Professional\MicTest\ReservedObjects\GlobalDictionary\ProgID", "Scripting.Dictionary","REG_SZ"
Set WshShell = Nothing
B、
GlobalDictionary.Add "ParamName", "ParamValue"
Msgbox GlobalDictionary.Item("ParamName")
GlobalDictionary.Item("ParamName")="***********"
Msgbox GlobalDictionary.Item("ParamName")
Msgbox GlobalDictionary.Exists("ParamName")
GlobalDictionary.Remove("ParamName")
Msgbox GlobalDictionary.Exists("ParamName")
8、关掉多余的IE窗口:
SystemUtil.CloseProcessByWndTitle "51testing", True
9、Execute 的用法,这个用法在一些特殊时候很有用的:
x="4"
Execute "Dim A_" & x
Execute "A_" & x &"=99"
Msgbox Eval("A_" & x)
~~~~~~~~~~~~~~~~~~~
10、GetLastError的介绍,看字面就是取运行最后一个错误:
x = GetLastError
msgbox(DescribeResult(x))
11、把weblist抓图下来:
Setting.WebPackage("ReplayType") = 2 'Default is 1
Browser(".").Page(".").WebList(".").Click
Desktop.CaptureBitmap "C:\Test.bmp",True
Setting.WebPackage("ReplayType") = 1
12、Reporter.ReportEvent的新用法:
Reporter.ReportEvent micPass, "TransactionNumber", "<DIV style='font-size: 7pt; color: white'>&</DIV>"&"<B> <FONT COLOR=#000000>"&transNumber&"</FONT></B>"
Reporter.ReportEvent micPass, "TransactionNumber", "<DIV style='font-size: 7pt; color: white'>&</DIV>"&"<B> <FONT COLOR=red>"&transNumber&"</FONT></B>"
13、For循环中step的用法:
For K = 1 To 10 step 2
msgbox k
Next
14、Option Explicit,大家都知道VB Script里面是可以不申明变量直接使用,但是有时候我们为了脚本的规范,尽量申明使用的变量,这样你就用一下Option Explicit吧
Option Explicit ' Force explicit variable declaration.
Dim MyVar ' Declare variable.
MyInt = 10 ' Undeclared variable generates error.
MyVar = 10 ' Declared variable does not generate error.
15、从TXT文件里面读取特定行的数据:
Dim fso, myfile,msg
Set fso=CreateObject("scripting.FileSystemObject")
Set myfile = fso.openTextFile("C:\login.txt",1,false)
'这里设置一个循环看需要读取第几行
for i=1 to 10
myfile.SkipLine
next
msg=myfile.ReadLine
myfile.close
分享到:
相关推荐
QTP编写代码样例 QTP编写代码样例 QTP编写代码样例 QTP编写代码样例
【QTP】QTP基础代码 供大家下载学习
列举QTP中常用基础代码 1 生产随机数列 第一种方法 CODE: [Copy to clipboard] randomize'更新反回的数据 funcation rand(k,n) n=int((k-1)*rnd+1) rand=n end funcation 第二种方法 CODE: [Copy to clipboard] n=...
给大家分享个经典的QTP实例,很不错,有用例和代码,还有截图,大家可以下载看看,本人也是个初学者,希望和大家一起学习,共勉,实例是网上资源,如果涉及到版权问题,请及时告知,谢谢。
一段qtp脚本代码 一段qtp脚本代码 一段qtp脚本代码 一段qtp脚本代码
QTP经典实例.rar
QTP经典面试题.pdf
qtp代码框架------一位高手的杰作,里面是根据EXCEL文件进行读取参数,并把结果写入EXCEL参数,其中还包括参数的验证
包含qtp测试工具的下载地址和qtp测试工具的详细使用教程
qtp支持哪些环境; qtp的对象库类型都有哪些; 什么是action split; 解释一下qtp是如何识别对象的;
本人调试无错的QTP订机票参数化测试代码
qtpQTP软件测试工具QTP基础代码收集1、将bug添加到QCDimTDConnectionSetTDConnection=CreateObject("TDApiOle.TDConnection")TDConnection.InitConnection..."bella","pino软件测试工具QTP基础代码收集1、将bug添加到...
QTP经典系列教程集锦,学习了一段时间,感觉不错,非常全面;
qtp 基础代码 例子
给大家一个最简单的登陆实例,通过循环和IF语句,控制程序的流程
qtp链接数据库的代码 qtp链接数据库的代码 qtp链接数据库的代码 qtp链接数据库的代码 qtp链接数据库的代码
《QTP自动化测试实践》源代码
给初级学习qtp的测试人员提供的在录制时不理解的描述信息
QTP连接各类数据库(SQL SERVER\ORACLE\DB2\SYBASE\MYSQL)代码
QTP自动化测试实践》源代码QTP自动化测试实践》源代码QTP自动化测试实践》源代码QTP自动化测试实践》源代码QTP自动化测试实践》源代码