风过无息 2007-5-9 16:15
QTP学习分享(更新20070728)
[b]1.在测试中我们使用QTP调试脚本的时候一般就是DEBUG或者MSGBOX察看一些信息,其实有时候也可以使用print来实现批量的察看信息但是不影响程序运行.[/b]
运行脚本:
[code]a="100"
print a[/code]
~~~~~~~~~~~~~~~~~~~~~~~~~
[b]2.取datatable特定行的数据可以这样使用[/b]
运行脚本:
[code]DataTable.GetSheet("Action1").GetParameter("test").ValueByRow(4) [/code]
~~~~~~~~~~~~~~~~~~
[b]3.Wait Seconds [, Milliseconds]可以精确到毫秒.[/b]
~~~~~~~~~~~~~~~~~~
[b]4.在自定义的function里面数组作为返回值.[/b]
运行脚本:
[code]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)[/code]
~~~~~~~~~~~~~~~
[b]5.计算一个操作的时间.[/b]
运行脚本:
[code]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)[/code]
~~~~~~~~~~~~~~~
[b]6.取得指定sheet(datatable)的行数和列数(也可以理解为参数个数)[/b]
[code]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."[/code]
~~~~~~~~~~
[b]7.一种设置全局变量的方法GlobalDictionary[/b]
'Part 1.
'***********************************************************************************************************
[code]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[/code]
'*********************************************************************************************************************
'Part 2.
'*****************************************************************************************
[code]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")[/code]
'*********************************************************************************************
~~~~~~~~~~~
[b]8.关掉多余的IE窗口[/b]
[code]SystemUtil.CloseProcessByWndTitle "51testing", True [/code]
~~~~~~~~~~~~~~~~~~
[b]9.Execute 的用法,这个用法在一些特殊时候很有用的.[/b]
[code]x="4"
Execute "Dim A_" & x
Execute "A_" & x &"=99"
Msgbox Eval("A_" & x)
~~~~~~~~~~~~~~~~~~~[/code]
[b]10.GetLastError的介绍,看字面就是取运行最后一个错误[/b]
[code]x = GetLastError
msgbox(DescribeResult(x)) [/code]
这样可以在程序里面判断程序运行时候是否出错了.
[b]~~~~~~~~~~~~~~~~~
11.把weblist抓图下来[/b]
[code]Setting.WebPackage("ReplayType") = 2 'Default is 1
Browser(".").Page(".").WebList(".").Click
Desktop.CaptureBitmap "C:\Test.bmp",True
Setting.WebPackage("ReplayType") = 1[/code]
~~~~~~~~~~~~~~~~~~~~~~~~~~
[b]12.Reporter.ReportEvent的新用法[/b]
transNumber = 12345
[code]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>"[/code]
~~~~~~~~~~~~~~~~~~~~~~~~~~
[b]13.For循环中step的用法[/b]
[code]For K = 1 To 10 step 2
msgbox k
Next[/code]
~~~~~~~~~~~~~~~~~~~~~~~
[b]14.Option Explicit,大家都知道VB Script里面是可以不申明变量直接使用,但是有时候我们为了脚本的规范,尽量申明使用的变量,这样你就用一下Option Explicit吧.[/b]
[code]Option Explicit ' Force explicit variable declaration.
Dim MyVar ' Declare variable.
MyInt = 10 ' Undeclared variable generates error.
MyVar = 10 ' Declared variable does not generate error.[/code]
~~~~~~~~~~~~~~~~~~~~~~~
[b]14.从TXT文件里面读取特定行的数据.[/b]
[code]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[/code]
~~~~~~~~~~~~~~~~~~~~~~~
[[i] 本帖最后由 风过无息 于 2007-7-29 14:22 编辑 [/i]]
eramyang 2007-5-9 16:22
GetParameter("test")中的test是那里来的?
风过无息 2007-5-9 16:36
是我参数的名字
[[i] 本帖最后由 风过无息 于 2007-5-9 16:42 编辑 [/i]]
higkoo 2007-5-9 21:36
有点开发的感觉
有点在做开发的感觉,有没实际一点的例子?sdlkfj3
mldyt0229 2007-5-10 09:39
回复
在测试中我们使用QTP调试脚本的时候一般就是DEBUG或者MSGBOX察看一些信息,其实有时候也可以使用print来实现批量的察看信息但是不影响程序运行.
=======================================================
在帮助中没有找到这个对象或者是函数,而且具体怎么用有没有例子呢?
alex_82712 2007-5-10 09:45
学习了。
Thanks for LZ
风过无息 2007-5-11 14:48
你随便定义一些需要显示的数据就好了.
i=100
msg="hello"
print i
print msg
在9.0的帮助里面有关于print的介绍.
htot05 2007-5-11 15:02
不错,msgbox的特点就在与暂停脚本运行和输出结果只能当时看,再想看就得重新运行,如果用Print的话,在一些条件下会比msgbox方便一些,好办法~~!!
dawee 2007-5-12 13:12
[quote]原帖由 [i]风过无息[/i] 于 2007-5-11 14:48 发表 [url=http://bbs.51testing.com/redirect.php?goto=findpost&pid=518525&ptid=75276][img]http://bbs.51testing.com/images/common/back.gif[/img][/url]
你随便定义一些需要显示的数据就好了.
i=100
msg="hello"
print i
print msg
在9.0的帮助里面有关于print的介绍. [/quote]
1.print方法只适用于 9.0以上版本还是?是属于QTP里面的方法还是VBS的方法?
2.print 以后的信息到哪里去了呢?是有个默认的文件保存还是?
如果想把print方法后获取的信息 输入到特定的文件,可否实现?如何实现?thanks
风过无息 2007-5-13 11:21
楼上的你可以自己把脚本运行一下就知道了
walker1020 2007-5-13 11:46
楼主经过一段时间的学习后,把自己的收获总结了出来,还无私地奉献了出来,值得学习!谢谢 风过无息!
风过无息 2007-5-14 18:27
谢谢斑竹的鼓励.
rivermen 2007-5-15 10:18
8.2里面没有print,那还有类似的方法吗?
风过无息 2007-5-15 11:01
你试过了吗?
chenjie021 2007-5-15 14:19
谢谢,楼主的总结
denisye 2007-5-15 22:08
谢谢楼主的总结,以前只知道用msgbox,今天学会了print这个好东东sdlkfj3
Sophie.zhang.cs 2007-5-16 13:55
弱弱的问一句,应该怎么运行这些语句阿?是在qtp直接运行吗?那不是要有一个url的吗 ?
风过无息 2007-5-17 14:47
新增一种设置全局变量的方法GlobalDictionary
rivermen 2007-5-17 16:32
我的8.2版本找不到 print
[attach]25570[/attach]
hxf 2007-5-18 16:30
8。2不支持print这个方法
stone821021 2007-5-18 16:52
我都是用reporter的.print 在8.2里不行!sdlkfj5
yuandjing 2007-5-22 17:05
楼主数个高手
全局变量也可以用环境变量实现,功能是一样的
zhaojie 2007-5-23 15:51
呵呵
brianq 2007-5-24 14:34
学一学!
dionysus 2007-5-28 23:10
Print是个不错的方法!
查了一下帮助 services.LogMessage() 这个方法可以往QTP的Test Results里面写报告,作用类似
风过无息 2007-5-29 10:12
楼上说的方法和Reporter.ReportEvent类似啊,不过又多了一个输出信息的方法了.
sunqiang1024 2007-6-5 16:45
谢谢楼主分享啊,呵呵
fwind1 2007-6-5 19:03
<strong>不错</strong>
jimmy2006.hi 2007-6-6 09:50
受益非浅,楼住加油~sdlkfj2
flyfly310 2007-6-6 15:16
2 datatable某行的值获取 (补充方法)
datatable.setcurrentrow(row)
a=datatable.rawvalue("column name","sheet name")
eg:
datatable.setcurrentrow(4)……设置当前行为第四行
a=datatable.rawvalue("test","action1")……获取action1sheet的test列的行值
newideaway 2007-6-7 17:45
回复 #30 flyfly310 的帖子
sdlkfj6
风过无息 2007-6-8 22:12
更新纪录20070608
增加GetLastError
5555 2007-6-9 21:22
ddddddddddddd
topor 2007-6-11 15:56
又学到新东东了~~~~sdlkfj3
walker1020 2007-6-13 09:45
风过无息 有心了,谢谢你!我把它移动到 [QTP精华区] 了
kkrt20032003 2007-6-15 13:21
lz 学得不错啊。 学习ing!!sdlkfj2
kitteylnm 2007-6-27 14:55
学习ing
感谢楼主
kitteylnm 2007-6-27 14:55
学习ing
学习ing
感谢楼主
风过无息 2007-7-7 10:38
更新纪录20070707
增加Reporter.ReportEvent的新用法
mjji23 2007-7-10 11:21
xiexie