作者:文青山
时间:2010-8-30
标题:我是如何使用QTP去测试的
注意:请尊重版权!
上接:http://www.51testing.com/index.php?uid-287227-action-viewspace-itemid-219449
B、主体脚本过程,此处可使用描述性编程来书写,如使用描述性编程,需从common文件中调用相关的对象库(描述性编程)
确定录制的主体过程,此过程我是通过录制实现的,此处代码为测试脚本的主体部分提供基础代码,即为C部分(下方)的扩展操作提供基础代码。
如:
‘起动浏览器,进入系统登录界面
'打开IE wqs592452,在不同的机器上需要更改一下
SystemUtil.Run "C:\Program Files\Internet Explorer\iexplore.exe","","C:\Documents and Settings\wqs592452","open"
Browser("Browser").Navigatehttp://10.9.146.182:8080/index.asp
‘点击登录链接
Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click
‘执行登录操作
Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("uname").Set “123”
Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("pwd").Set “123456”
Browser("Browser").Page("在线考试系统").Frame("main").WebButton("登 录").Click
'返回登录界面,执行下一轮数据的操作
Browser("Browser").Page("在线考试系统").Frame("top").Link("【注销登录】").Click
Browser("Browser").Dialog("Microsoft Internet Explorer").WinButton("确定").Click
Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click
C、按照case修改脚本,主要调用库函数中的写入Excel单元格的函数Write_Excel(pathway,sheetname,x,y,content)读取单元格的函数ReadExcelCell(file,sheet,x,y)以及截图函数Qtp_Capture,注意Qtp_Capture应在Write_Excel之前,否则截图时可能为读取Excel的界面
‘点击登录链接
1、 '验证loginCase文档中login_001
Browser("Browser").Page("在线考试系统").Frame("top").Link("【登录系统】").Click
‘如果登录后某对象存在,则case文件login_001 Pass,否则Fail,并截图
If Browser("Browser").Page("在线考试系统").Frame("main").WebButton("登 录").Exist Then
'如果存在此对象,则将case中的actualresults置为pass
Write_Excel casePath,"login",2,"D","Pass"
Else
'如果出现错误,则截图并保存到指定文件夹中
QTP_Capture capturePath,"login_001"
'如果不存在此对象,则将case中的actualresults置为fail
Write_Excel casePath,"login",2,"D","Fail"
‘出现错误后,说明错误的原因
Write_Excel casePath,"login",2,"E","登录系统链接失效"
End If
2、'验证loginCase文档中login_002
‘利用描述性编程,查看width in characters对象是否存在,并且为30
If Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("name:=uname","width in characters:=30").Exist then
'如果存在此对象,则将case中的actualresults置为pass
Write_Excel casePath,"login",3,"D","Pass"
else
'如果出现错误,则截图并保存到指定文件夹中
QTP_Capture capturePath,"login_002"
'如果存在此对象,则将case中的actualresults置为fail
Write_Excel casePath,"login",3,"D","Fail"
‘出现错误后,说明错误的原因
Write_Excel casePath,"login",3,"E","用户名输入框未设置为30位"
end if
3、’验证loginCase文档中login_003
‘利用描述性编程,查看width in characters对象是否存在,并且为30
If Browser("Browser").Page("在线考试系统").Frame("main").WebEdit("name:=pwd","width in characters:=30").Exist then
'如果存在此对象,则将case中的actualresults置为pass
Write_Excel casePath,"login",3,"D","Pass"
else
'如果出现错误,则截图并保存到指定文件夹中
QTP_Capture capturePath,"login_002"
'如果存在此对象,则将case中的actualresults置为fail
Write_Excel casePath,"login",3,"D","Fail"
‘出现错误后,说明错误的原因
Write_Excel casePath,"login",3,"E","用户名输入框未设置为30位"
end if