转贴一个高人的QTP笔记供大家学习。
文章比较长,一共三部分:
1、连接数据库查询例子,无参数化
//查询收文操作,通过数据库查询记录数是否正确
//1、输出记录数值,例如78条 2、获取输出的记录数值 3、连接数据库,查询记录数
4、输出记录数值和从数据库中查询记录数值,相比较,相等则成功,不等则失败
Browser(“湛江信息化测试登录”).Page(“湛江东兴石油企业有限公司办公自动化系统”).Frame(“mainFrame”).Output CheckPoint(“78”)
Dim mm
‘mm=DataTable.GlobalSheet.GetParameter(“mainFrameOutput_Text_out”).Value
//注释,获取datatable值与DataTable(“mainFrameOutput_Text_out”, dtGlobalSheet)一致
mm=DataTable(“mainFrameOutput_Text_out”, dtGlobalSheet)
MsgBox mm
Dim res,cmd,sql
Set res=createobject(“adodb.recordset”)
Set cmd=createobject(“adodb.command”)
Cmd.activec
Cmd.CommandType = 1
sql=”select count(*) from oa_receivebumf where BUMFNAME like ‘%收文测试%'”
‘sql=”select count(*) from oa_receivebumf where BUMFNAME='”&nn&”‘”
//注释,sql语句,等于时sql语句
// sql=”select count(*) from oa_receivebumf where BUMFNAME like ‘%nn%'” //like时sql语句
Cmd.CommandText = sql
Set res = Cmd.Execute()
//msgbox res(“name”)
MsgBox res(0)
If Cstr(res(0)) = Cstr(mm)Then
Reporter.ReportEvent micPass, “test”, “查询成功”
else
Reporter.ReportEvent micfail, “test”, “查询失败”
End If
Set res = nothing
Set cmd.ActiveConnection = nothing
Set Cmd= nothing
Tag: