我是如何使用QTP去测试的(三)
上一篇 / 下一篇 2010-08-30 15:15:54 / 个人分类:Bug那些事儿
上接http://www.51testing.com/index.php?uid-287227-action-viewspace-itemid-21945051Testing软件测试网 nu0|S2Y
4、’验证loginCase文档中login_004至login_009
For i=2 to 7
‘读取data中,login的数据
Dim username,password,expected
username=ReadExcelCell(dataPath, "login", i, 1)
password=ReadExcelCell(dataPath, "login", i, 2)
expected=ReadExcelCell(dataPath,"login",i,3)
‘执行登录操作,将读取到的username参数化给下面的数据
Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("username").Set username
Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("pwd").Set password
Browser("Browser").Page("在线考试系统").Frame("main").WebButton("登 录").Click
‘判断登录是否成功的文本字符
popok=Browser("Browser").Page("在线考试系统").Frame("left").WebElement("考生姓名:123状 态:已登录").Exist(3)
popno=Browser("Browser").Page("在线考试系统").Frame("main_2").WebElement("操作失败").Exist(3)
‘依据期望结果进行判断
If expected="ok" Then
If popok Then
'将数据源中的期待结果写为pass
Write_Excel dataPath,"login",i,"D","Pass"
'将此结果在测试用例中进行体现
Write_Excel casePath,"login",i+3,"D","Pass"
'返回登录界面,执行下一轮数据的操作
Browser("Browser").Page("在线考试系统").Frame("top").Link("【注销登录】").Click
Browser("Browser").Dialog("Microsoft Internet Explorer").WinButton("确定").Click
Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click
else
'如果出现错误,则截图并保存到指定文件夹中
QTP_Capture capturePath,"login_"&i+3
'将数据源中的期待结果写为fail
Write_Excel dataPath,"login",i,"D","Fail"
Write_Excel dataPath,"login",i,"E","正确用户名和密码登录失败"
'将此结果在测试用例中进行体现
Write_Excel casePath,"login",i+3,"D","Fail"
Write_Excel casePath,"login",i+3,"E","正确用户名和密码登录失败"
'出错后,重新进入登录界面
Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click
End If
else
If popno Then
'msgbox "no"
'将数据源中的期待结果写为pass
Write_Excel dataPath,"login",i,"D","Pass"
'将此结果在测试用例中进行体现
Write_Excel casePath,"login",i+3,"D","Pass"
‘pass后返回登录界面,继续执行下一轮操作
Browser("Browser").Page("在线考试系统").Frame("main_2").WebButton("返回上一页").Click
elseif popok then
'如果出现错误,则截图并保存到指定文件夹中
QTP_Capture capturePath,"login_"&i+3
'将数据源中的期待结果写为fail
Write_Excel dataPath,"login",i,"E","错误用户名或密码,登录成功"
' '将此结果在测试用例中进行体现
Write_Excel casePath,"login",i+3,"E","错误用户名或密码,登录成功"
'返回登录界面,继续验证相关数据
Browser("Browser").Page("在线考试系统").Frame("top").Link("【注销登录】").Click