[ 本帖最后由 applebugs 于 2006-8-19 14:30 编辑 ]作者: xiaonan 时间: 2006-8-19 22:48
场景1:"我的初步想法,可能需要QTP去和数据库交互去验证,但很难找到这方面的实例,所以到这里来和高手探讨,向大家学习呀。。。"
的确可以通过QTP直接去连数据库来取值.其实也就是用vbscript与数据库通过ado来连接.如果楼主不清楚代码怎么写,可以搜一下帖子,这方面的太多了,怎么会找不到呢?这里先给你一段.
Dim res,cmd,sql
Set Res=createobject("adodb.recordset")
Set Cmd=createobject("adodb.command")
Cmd.activeconnection="Provider=SQLOLEDB.1;Password=111111;Persist Security Info=True;User ID=sa;Initial Catalog=xhq;Data Source=192.168.191.142" '这句话是连接数据库的数据源,要做修改
Cmd.CommandType = 1
sql="selec t * from 表 where name=username"
Cmd.CommandText = sql
Set res = Cmd.Execute()
Set res = nothing
Set cmd.ActiveConnection = nothing
Set Cmd= nothing
场景2:取到两个时间后,你用if语句来判断一下就行了,然后加Reporter.ReportEvent 就会把结果打到结果记录里去了.
if 预定开始时间=预定结束时间 then
Reporter.ReportEvent 0, "验证正确"," pass"
else
Reporter.ReportEvent 1, "验证错误"," failed"
end if
实例:
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;
3.SQL语句实例
source:SQL语句
SELECT HR_LANGUAGE_TYPE.LANGUAGE_NAME FROM DCWORK.HR_LANGUAGE_TYPE HR_LANGUAGE_TYPE WHERE (HR_LANGUAGE_TYPE.LANGUAGE_NAME='中文') ORDER BY HR_LANGUAGE_TYPE.LANGUAGE_NAME作者: applebugs 时间: 2006-8-23 10:29 标题: 经整理后QTP与oracle连接 Dim Cnn
Dim Rst
Dim strCnn
Dim TestNumberOne
Dim TestNumberTwo
strCnn = "Provider=MSDAORA.1;Data Source=yourtnsname;Password=yourpassword;User ID=youruserid;Persist Security Info=True"
Set Cnn = CreateObject("ADODB.Connection")
Cnn.Open strCnn
Set Rst =CreateObject("ADODB.Recordset")
Rst.open "select *From table_name where id in (300041, 300040)", Cnn
Rst.MoveFirst
Do while Rst.EOF <> True
TestNumberOne = Trim(Rst.Fields(8))
TestNumberTwo = Trim(Rst.Fields(9))
msgbox TestNumberOne
msgbox TestNumberTwo
If TestNumberOne < TestNumberTwo Then
Reporter.ReportEvent micPass, "testing", "开始时间小于结束时间"
else
Reporter.ReportEvent micFail, "testing", "开始时间大于等于结束时间"
End If