本来是来学习QTP的,结果发现我需要的文章需要权限10才能看到,超级郁闷……踩过也不能不留下点东东,转贴一个高人的QTP笔记供大家学习。
文章比较长,一共三部分:
1、连接数据库查询例子,无参数化
//查询收文操作,通过数据库查询记录数是否正确
//1、输出记录数值,例如78条2、获取输出的记录数值3、连接数据库,查询记录数
4、输出记录数值和从数据库中查询记录数值,相比较,相等则成功,不等则失败
Browser("湛江信息化测试登录").Page("湛江东兴石油企业有限公司办公自动化系统").Frame("mainFrame").[color=#ff00ff]OutputCheckPoint("78")[/color] [color=#ff00ff]Dimmm [/color]'mm=DataTable.GlobalSheet.GetParameter("mainFrameOutput_Text_out").Value //注释,获取datatable值与DataTable("mainFrameOutput_Text_out",dtGlobalSheet)一致 [color=#ff00ff]mm=DataTable("mainFrameOutput_Text_out",dtGlobalSheet) [/color]MsgBoxmm Dimres,cmd,sql Setres=createobject("adodb.recordset") Setcmd=createobject("adodb.command") Cmd.activec Cmd.CommandType=1 sql="selectcount(*)fromoa_receivebumfwhereBUMFNAME[color=#ff0000]like'%收文测试%'" [/color]'sql="selectcount(*)fromoa_receivebumfwhereBUMFNAME='"&nn&"'" //注释,sql语句,等于时sql语句 //sql="selectcount(*)fromoa_receivebumfwhereBUMFNAMElike'%nn%'"//like时sql语句 Cmd.CommandText=sql Setres=Cmd.Execute() //msgboxres("name") MsgBoxres(0) [color=#ff00ff]IfCstr(res(0))=Cstr(mm)Then[/color] Reporter.ReportEventmicPass,"test","查询成功" else Reporter.ReportEventmicfail,"test","查询失败" EndIf Setres=nothing Setcmd.ActiveConnection=nothing SetCmd=nothing |
2、登记用户,查看是否登记成功
//登记用户,查询用户是否存在在数据库中
1、参数化2、取参数化值3、查询语句中,赋值给查询条件
4、从数据库中查询出用户名,与参数化中值做比较
脚本如下:
Browser("测试登录").Page("办公自动化系统").Frame("mainFrame_2").WebEdit("addressVO.name").[color=#0000ff]SetDataTable("p_Text",dtGlobalSheet)[/color] [color=#0000ff]Dimxname xname=DataTable("p_Text",dtGlobalSheet) MsgBoxxname[/color] Dimres,cmd,sql Setres=createobject("adodb.recordset") Setcmd=createobject("adodb.command") Cmd.activec Cmd.CommandType=1 sql="selectnamefromaddress_listtwherename='[color=#0000ff]"&xname&"'" [/color]Cmd.CommandText=sql Setres=Cmd.Execute() 'msgboxres("name") MsgBoxres(0) Setres=nothing Setcmd.ActiveConnection=nothing SetCmd=nothing |