1、1)生产随机数列第一种方法randomize更新反回的数据funcation rand(k,n)n=“int(k-1)*rnd+1) rand=nend 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.1
2、68.0.1;DBQ=testdb;user id=test; password=test“Conn.open strSet Rs = CreateObject (“ADODB.Recordset“ )sql= “select * from user_table t where table_name = XXX “Rs.open sql,conn,1,34)QTP如何测试鼠标右键菜单以 QTP附带的订票网站 sample为例,edit 控件 username鼠标右键,点击 paste(第4个菜单项)cur_replay_type = Setting.WebPackage(“ReplayType
3、“)Run mouse operations using the mouse, if 1 using browser eventsSetting.WebPackage(“ReplayType“) = 2 Browser(“Browser“).Page(“Welcome:MercuryTours“).WebEdit(“userName“).Click micRightBtnSetting.WebPackage(“ReplayType“) = cur_replay_typeindex=4Set WshShell = CreateObject(“Wscrpt.Shell“)For i = 1 To
4、indexWshShell.sendKeys “DOWN“NextWshShell.sendKeys “ENTER“Set WshShell = nothing5)QTP测试页面字体颜色的办法set bj = Browser().Page().WebElement().Object Get the objectset iStyle= obj.currentstyle Get the attributesColor = iStyle.color6)从 QC自动启动 qtp如何自动加载插件此函数用于加载指定 Test所有的插件,若要运行 Test可自己加个 qtApp.Test.RunFuncti
5、on Load_Addins(testPath)Dim qtApp As QuickTest.ApplicationDim blnNeedChangeAddinsDim arrTestAddinsSet qtApp = CreateObject(“QuickTest.Application“)arrTestAddins = qtApp.GetAssociatedAddinsForTest(testPath)blnNeedChangeAddins = FalseFor Each testAddin In arrTestAddinsIf qtApp.Addins(testAddin).Status
6、 “ 设置”“环境”,在变量类型中选择“用户自定义”,然后进行添加,可以对添加的变量全部导出,导出的文件为.xml 格式的文档。既然可以导出,那么必然可以导入.xml 文件,你可以在该对话框中的选中“从外部文件导入”,然后添加其文件路径即可。(当然这些操作都可以直接使用脚本来实现,如:Environment.LoadFromFile(“FileName”)xml文件格式如下:/ 变量定义起始标识aa / 变量名称11 / 变量值/ 变量定义结束标识bb22使用的脚本Dim aParam3aParam3=Environment.Value(“aa”) / 调用环境变量msgbox aParam3
7、16)弹出输入窗口Dim InputInput = InputBox(“Enter your name“)MsgBox (“You entered: “ SERVER=数据库 IP地址;UID=用户名;PWD=密码;APP=Microsoft Office 2003;WSID=本地主机名;DATABASE=数据库名实例:DRIVER=SQL Server;SERVER=10.160.11.10;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJHLJUN;DATABASE=dcwork2.本地已创建数据源的方式DSN=数据源名称;UID=用户名;PW
8、D=密码;APP=Microsoft Office 2003;WSID=数据库的主机名;DATABASE=数据库名实例:DSN=LocalServer;UID=sa;PWD=sa;APP=Microsoft Office 2003;WSID=RJDCWORKTEST;DATABASE=dcwork3.SQL语句实例(从数据库表 HR_LANGUAGE_TYPE中,查询字段语言名称LANGUAGE_NAME,条件语言名称中文,按语言名称升序排序结果)SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM dcwork.dbo.HR_LANGUAGE_TYPE HR_
9、LANGUAGE_TYPE WHERE (HR_LANGUAGE_TYPE.LANGUAGE_NAME=中文) ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME二、DB2 格式:(本地至少安装 DB2 Run-Time Client Lite)connectionstring(连接字符串):1.本地没有创建数据源的方式DRIVER=IBM DB2 ODBC DRIVER;UID=用户名;PWD=密码;MODE=SHARE;DBALIAS=数据库名;实例:DRIVER=IBM DB2 ODBC DRIVER;UID=db2admin;PWD=db2admin;MOD
10、E=SHARE;DBALIAS=DCWORK;2.本地已创建数据源的方式DSN=数据源名称;UID=用户名;PWD=密码;MODE=SHARE;DBALIAS=DCWORK;实例:DSN=DWCORKDB2;UID=db2admin;PWD=db2admin;MODE=SHARE;DBALIAS=DCWORK;3.SQL语句实例SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM DB2ADMIN.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE (HR_LANGUAGE_TYPE.LANGUAGE_NAME=中文) ORDER B
11、Y HR_LANGUAGE_TYPE.LANGUAGE_NAME三、Oracle 格式:(本地需要安装 Oracle ODBC DRIVER)connectionstring(连接字符串):1.本地没有创建数据源的方式DRIVER=Oracle in OraHome92;SERVER=数据库服务名;UID=用户名;PWD=密码;DBQ=数据库名;DBA=W;APA=T;EXC=F; XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=Lo;BAM=IfAllSuccessful;MTS=F;MDI=Me;CSR=F;FWC=F
12、;PFC=10;TLO=O;实例:DRIVER=Oracle in OraHome92;SERVER=DCWORK;UID=DCWORK;PWD=DCWORK;DBQ=DCWORK;DBA=W;APA=T;EXC=F;XSM=Default;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=Lo;BAM=IfAllSuccessful;MTS=F;MDI=Me;CSR=F;FWC=F;PFC=10;TLO=O;2.本地已创建数据源的方式DSN= 数据源名称;UID=用户名;PWD=密码;DBQ=数据库名;DBA=W;APA=T;EXC=F;FEN=
13、T;QTO=T;FRC=10; FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;实例:DSN=dcworkoracle;UID=DCWORK;DBQ=DCWORK;DBA=W;APA=T;EXC=F;FEN=T;QTO=T;FRC=10;FDL=10;LOB=T;RST=T;GDE=F;FRL=F;BAM=IfAllSuccessful;MTS=F;MDI=F;CSR=F;FWC=F;PFC=10;TLO=0;3.SQL语句实例SELECT HR_LANGUAGE_T
14、YPE.LANGUAGE_NAME FROM DCWORK.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE (HR_LANGUAGE_TYPE.LANGUAGE_NAME=中文) ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME四,mysqlSet Conn = CreateObject(“ADODB.Connection“ )str=“DRIVER=MySQL ODBC 3.51 Driver;SERVER=192.168.1.100;DATABASE=wp_blog;user id=zzz ; password=123456“C
15、onn.open strSet Rs = CreateObject (“ADODB.Recordset“ )sql = “select * from wp_blog.blg_webcategory limit 0, 5000;“Rs.open sql,conn,1,3If (not Rs.eof) thenRs.MoveFirstMsgBox Rs(0)MsgBox Rs(1)MsgBox Rs(2)MsgBox Rs(3)end ifRs.closeSet Rs = NothingConn.closeSet Conn = Nothing五. accessSet Conn = CreateObject(“ADODB.Connection“ )str=“Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:/db1.mdb“Conn.open strSet Rs = CreateObject(“ADODB.Recordset“)