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
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
End If
Next
D、执行脚本后,关闭网页和发送相关文档到相关人员的邮箱之中
'执行完之后,关闭网页
Browser("Browser").Close
'执行完此模块的测试后,将测试结果发送到指定的邮件之中
Dim Body '邮件的内容
Dim sendto'收件人的地址
Dim subject '邮件主题
Body="Hi:"&vbCrLf&"此文件为本次自动化测试的Case结果。请查收!谢谢!"&vbCrLf&vbCrLf&"from qwen"&vbCrLf&Now()
sendto="wen.qingshan@byd.com"
subject=now()&"自动化测试的结果"
SendMail sendto,subject, Body, casePath
一直以来不清楚大家是怎么去使用QTP测试的,甚至也不太清楚我这么去做是否能称得上算一个QTP的框架,不过我就是这样使用QTP去做测试的。最后,十分感谢您能够有耐心地看到这里,谢谢。
另外,不知道是不是因为51这个发表日志框将回车后剩余的空格也认成字符了, 一次发表所有内容老被截断,这点挺另人晕的.
作者:文青山
2010-8-30