QTP实例——系统登陆界面
'登陆系统Browser("XX系统").Page("XXpage").WebEdit("WebEdit").Set DataTable("userName", dtGlobalSheet)'输入用户名Browser("XX系统").Page("XXpage").WebEdit("WebEdit_2").Set DataTable("passWord", dtGlobalSheet) '输入密码'输入验证码Dim inputinput = Inputbox("请输入验证码:")Browser("XX系统").Page("XXpage").WebEdit("WebEdit_3").Set input'点击登陆按钮Browser("XX系统").Page("XXpage").WebElement("WebElement").Click'用户登陆——测试用例脚本Dim expected,username,passwordexpected=DataTable.RawValue("Expected",dtGlobalSheet)'获取期望值username=DataTable.RawValue("userName",dtGlobalSheet)'获取userName的数据password=DataTable.RawValue("passWord",dtGlobalSheet)'获取passWord的值'如果给定的数据为空,则只检查提示语If username<>"" and password<>"" ThenIf expected="pass" Then'如果期望值为ok,则说明登陆成功Reporter.ReportEvent micPass,"用户名:"&(DataTable.RawValue("userName",dtGlobalSheet)&",密码:"&DataTable.RawValue("passWord",dtGlobalSheet))," 正确用户名或密码,登录成功"elseif expected="fail" then '如果期望值为no,则继续判断登录处理Reporter.ReportEvent micDone,"用户名:"&(DataTable.RawValue("userName",dtGlobalSheet)&",密码:"&DataTable.RawValue("passWord",dtGlobalSheet))," 用户名或密码错误,登录失败"Browser("XX系统").Dialog("来自网页的消息").WinButton("确定").Click '点击提示框中的确定按钮elsereporter.ReportEvent micDone, "else brach", "数据源Expected中有除pass或fail以外的其它值!"End IfelseIf expected="pass" ThenReporter.ReportEvent micFail,"用户名:"&(DataTable.RawValue("userName",dtGlobalSheet)&",密码:"&DataTable.RawValue("passWord",dtGlobalSheet))," 数据为空,不能登陆成功"elseif expected="fail" thenIf username="" Thenreporter.ReportEvent micDone, "empty userName", "用户名不能为空"Browser("XX系统").Dialog("来自网页的消息").WinButton("确定").Click '点击提示框中的确定按钮elsereporter.ReportEvent micDone, "empty password", "密码不能为空"Browser("XX系统").Dialog("来自网页的消息").WinButton("确定").Click '点击提示框中的确定按钮End Ifelsereporter.ReportEvent micDone, "else brach", "数据源Expected中有除pass或fail以外的其它值!"End IfEnd If'关闭窗口Browser("XX系统").Page("XXpage").SyncBrowser("XX系统").CloseAllTabs?