QTP - 脚本相关收集
来源:互联网 发布:经济学考研视频知乎 编辑:程序博客网 时间:2024/05/17 00:14
1)生产随机数列
第一种方法
randomize'更新反回的数据
funcation rand(k,n)
n="int((k-1)*rnd+1) rand=n
end funcation
第二种方法
n="randomnumber.value(1,255)
2)wintreeview一些操作
选择一个条目:wintreeview.select(item)'根是0
根的名称:wintreeview.getitem(0)
3)QTP中用代码连接数据库
Set Conn = CreateObject("ADODB.Connection" )
str="DRIVER=Oracle in OraHome92;SERVER=192.168.0.1;DBQ=testdb;user id=test; password=test"
Conn.open str
Set Rs = CreateObject ("ADODB.Recordset" )
sql = "select * from user_table t where table_name = 'XXX' "
Rs.open sql,conn',1,3
4)QTP如何测试鼠标右键菜单
以QTP附带的订票网站sample为例,edit控件username鼠标右键,点击paste(第4个菜单项)
cur_replay_type = Setting.WebPackage("ReplayType")
'Run mouse operations using the mouse, if 1 using browser events
Setting.WebPackage("ReplayType") = 2
Browser("Browser").Page("Welcome: Mercury Tours").WebEdit("userName").Click micRightBtn
Setting.WebPackage("ReplayType") = cur_replay_type
index=4
Set WshShell = CreateObject("Wscrīpt.Shell")
For i = 1 To index
WshShell.sendKeys "{DOWN}"
Next
WshShell.sendKeys "{ENTER}"
Set WshShell = nothing
5)QTP测试页面字体颜色的办法
set ōbj = Browser().Page().WebElement().Object
' Get the object
set iStyle= obj.currentstyle
' Get the attribute
sColor = iStyle.color
6)从QC自动启动qtp如何自动加载插件
'此函数用于加载指定Test所有的插件,若要运行Test可自己加个qtApp.Test.Run
Function Load_Addins(testPath)
Dim qtApp 'As QuickTest.Application
Dim blnNeedChangeAddins
Dim arrTestAddins
Set qtApp = CreateObject("QuickTest.Application")
arrTestAddins = qtApp.GetAssociatedAddinsForTest(testPath)
blnNeedChangeAddins = False
For Each testAddin In arrTestAddins
If qtApp.Addins(testAddin).Status <> "Active" Then
blnNeedChangeAddins = True
Exit For
End If
Next
If qtApp.Launched And blnNeedChangeAddins Then
qtApp.Quit