利用QTP在WEB应用程序上进行简单的猴子测试
2010-01-07 22:22
405 查看
利用QTP可以在WEB应用程序上进行简单的猴子测试
,例如遍历主页面中的每一个链接,每次选择一个链接进行点击操作,然后回退到主页面,再选择下一个链接进行点击,如此类推。在测试过程中,把每个动作写入测试日志中。
下面代码摘自QTP的CodeSamplesPlus并做了一些必要的修改:
' 启动IE浏览器
SystemUtil.Run "iexplore.exe"
' save the Report Filter mode
OldFilter = Reporter.Filter
Reporter.Filter = 2 ' Enables Errors Only
' 链接描述
Set Desc = Description.Create()
Desc("html tag").Value = "A"
Desc("href").Value = "http://blog.csdn.net/Testing_is_believing/category/.*"
Set BrowserObj = Browser("creationtime:=0")
' 导航到指定页面
BrowserObj.Navigate "http://blog.csdn.net/Testing_is_believing/category/357781.aspx"
Set PageObj = BrowserObj.Page("index:=0")
' 开始“猴子测试”
call EnumerateApp(PageObj, Desc, "Click", "ReportPage", "BrowserBack")
Reporter.Filter = OldFilter ' returns the original filter
' 遍历整个程序,执行指定的操作,例如点击每个链接
Function EnumerateApp(ParentObj, Desc, OperationMethod, PostOperationMethod, RestoreMethod)
dim ObjCol, CurrentObj, idx
idx = 0
' retrieve a collection of all the objects of the given descrition 按指定的描述取得所有子对象
Set ObjCol = ParentObj.ChildObjects(Desc)
Do While (idx < ObjCol.Count)
' get the current object
set CurrentObj = ObjCol.item(idx)
' perform the desired operation on the object 执行指定的操作,例如Click
eval("CurrentObj." & OperationMethod)
' perform the post operations (after the object operation) 执行完指定的操作后需要做的动作,例如写入测试日志
eval(PostOperationMethod & "(ParentObj, CurrentObj)")
' Return the application to the original state 让程序回到初始状态,例如让浏览器导航回退到主页面
eval(RestoreMethod & "(ParentObj, CurrentObj)")
idx = idx + 1
' reretrieve the collection of objects
' (as the application might have changed)
Set ObjCol = ParentObj.ChildObjects(Desc)
Loop
End Function
' 写测试日志
Function ReportPage(ParentObj, CurrentObj)
dim FuncFilter, PageTitle
PageTitle = ParentObj.GetROProperty("title")
FuncFilter = Reporter.Filter
Reporter.Filter = 0
Reporter.ReportEvent 0, "Page Information", "page title " & PageTitle
Reporter.Filter = FuncFilter
End Function
' 让浏览器按回退键
Function BrowserBack(ParentObj, CurrentObj)
On Error Resume Next
BrowserObj.Back
End Function
,例如遍历主页面中的每一个链接,每次选择一个链接进行点击操作,然后回退到主页面,再选择下一个链接进行点击,如此类推。在测试过程中,把每个动作写入测试日志中。
下面代码摘自QTP的CodeSamplesPlus并做了一些必要的修改:
' 启动IE浏览器
SystemUtil.Run "iexplore.exe"
' save the Report Filter mode
OldFilter = Reporter.Filter
Reporter.Filter = 2 ' Enables Errors Only
' 链接描述
Set Desc = Description.Create()
Desc("html tag").Value = "A"
Desc("href").Value = "http://blog.csdn.net/Testing_is_believing/category/.*"
Set BrowserObj = Browser("creationtime:=0")
' 导航到指定页面
BrowserObj.Navigate "http://blog.csdn.net/Testing_is_believing/category/357781.aspx"
Set PageObj = BrowserObj.Page("index:=0")
' 开始“猴子测试”
call EnumerateApp(PageObj, Desc, "Click", "ReportPage", "BrowserBack")
Reporter.Filter = OldFilter ' returns the original filter
' 遍历整个程序,执行指定的操作,例如点击每个链接
Function EnumerateApp(ParentObj, Desc, OperationMethod, PostOperationMethod, RestoreMethod)
dim ObjCol, CurrentObj, idx
idx = 0
' retrieve a collection of all the objects of the given descrition 按指定的描述取得所有子对象
Set ObjCol = ParentObj.ChildObjects(Desc)
Do While (idx < ObjCol.Count)
' get the current object
set CurrentObj = ObjCol.item(idx)
' perform the desired operation on the object 执行指定的操作,例如Click
eval("CurrentObj." & OperationMethod)
' perform the post operations (after the object operation) 执行完指定的操作后需要做的动作,例如写入测试日志
eval(PostOperationMethod & "(ParentObj, CurrentObj)")
' Return the application to the original state 让程序回到初始状态,例如让浏览器导航回退到主页面
eval(RestoreMethod & "(ParentObj, CurrentObj)")
idx = idx + 1
' reretrieve the collection of objects
' (as the application might have changed)
Set ObjCol = ParentObj.ChildObjects(Desc)
Loop
End Function
' 写测试日志
Function ReportPage(ParentObj, CurrentObj)
dim FuncFilter, PageTitle
PageTitle = ParentObj.GetROProperty("title")
FuncFilter = Reporter.Filter
Reporter.Filter = 0
Reporter.ReportEvent 0, "Page Information", "page title " & PageTitle
Reporter.Filter = FuncFilter
End Function
' 让浏览器按回退键
Function BrowserBack(ParentObj, CurrentObj)
On Error Resume Next
BrowserObj.Back
End Function
相关文章推荐
- 利用javascript在Siebel HI环境下进行简单的测试
- Win7下的使用QTP进行猴子测试的性能日志实现方法
- 利用monkey工具进行简单自动化测试
- 利用AIDA64对电脑进行简单的稳定性测试的技巧分享
- *简单脚本测试--利用date进行文件的创建*
- Win7下的使用QTP进行猴子测试的性能日志实现方法
- 利用console进行简单的js性能测试
- 利用xor特点进行简单加密解密
- 利用Junit4进行程序模块的测试,回归测试
- win8.1上wamp环境中利用apache自带ab压力测试工具使用超简单讲解
- 利用TTCN进行协议测试的一种方法
- 使用node进行简单模块化demo测试
- 利用C#开发web应用程序时,对注册表进行操作提示没有权限的解决办法
- 怎么利用jira的Issue style 的可定制性来进行需求和测试用例方面的管理与testLink集成
- 利用sockets协议进行性能测试
- 图解在VS2005利用NUnit进行测试
- 【转】利用JMeter进行压力测试
- Jmeter进行简单mysql数据库测试
- 利用Spring Insight + JMeter 对Web应用进行压力测试和性能评估
- 利用Python进行性能测试(上)