QTP场景恢复 函数调用

上一篇 / 下一篇  2014-07-09 14:03:41 / 个人分类:qtp

当'列表或菜单中找不到选项'时如何创建场景恢复方案。   此例中,我们会定义一个函数来处理错误。场景恢复函数的默认语法如下:
1.Function fnRecovery(Object, Method, Arguments, retVal)
2.'Error Handling Code
3.End Function
  下面给出fnRecovery 中每个参数的解释:
1.Object as Object: The object of the current step. '当前步骤的对象
2.Method as String: The method of the current step. '当前步骤的方法
3.Arguments as Array: The actual method's arguments. '方法的实参
4.Result as Integer: The actual method's result. '方法的实际结果

  我们使用以下函数处理报错场景:

01.Function Recovery_ListItemIsNotFound(Object, Method, Arguments, retVal)
02.Dim sAllItems, arrAllItems, intItem
03. 
04.With Object
05.'Retrieve all items from the Listbox
06.sAllItems = .GetROProperty('all items')
07.'Split 'all items' using a delimiter ';' into an array
08.arrAllItems = Split(sAllItems, ';')
09. 
10.'Select a random number
11.intItem = RandomNumber.Value(LBound(arrAllItems), UBound(arrAllItems))
12..Select '#' & intItem
13. 
14.Reporter.ReportEvent micInfo, 'ListItemIsNotFound''Item: ' & .GetROProperty('value')
15.End With
16.End Function

  Recovery_ListItemIsNotFound,顾名思议,如果WebList对象中不存在列表项,执行恢复操作。这中从错误在Web应用程序中是很常见的,WebList中的项往往随输入而更改。

    场景恢复创建入口:单击菜单栏 资源(Resources)->恢复方案管理器(Recovery Scenario Manager)。 RecoveryScenarioMenu 点击后,可以看到以下窗口:

 Recovery Scenario Wizard

在窗口中,点击下面的按钮,可以调用场景恢复向导: 

\

Recovery Scenario Wizard - Welcome

场景恢复向导 - 欢迎界面

 当上面的界面打开后: 

点击 Next 选择 Test Run Error 做为触发事件

\ 点击 Next 选择‘Test Run Error: Item in list or menu not found in the Error Listbox

\ 点击 Next -> Next ,导航到 恢复操作(Recovery Operation)界面

\ 选择 Function Call ,点击 Next

\ 选择恢复操作函数的存储库.
\ 选择 'Define New Function',在编辑区粘贴Recovery_ListItemIsNotFound 函数;若所选库中已存在函数,可选择'Select function',并在下拉框中选择函数

Define New Function

定义新函数

点击 Next,回到'Recovery Operations'页面 确保'Add Another Recovery Scenario'多选框未被选中,点击 Next.

\ Under Post-Recovery Test Run Options, select proceed to next step.更多选项详解参考http://www.cnblogs.com/sylvia-liu/p/3706287.html

\ 给场景命名,Click Next

\ 最后, 检查选项: Add Scenario to current test,点击 Finish.保存并关闭。【补充:将该场景恢复方案应用于其他测试,File->setting->Recovery,选择场景方案】

  我们将在下面的 WebList中选择一个不存在的值;以下为源代码。查看列表下拉项,你会发现'Rational Robot'实际不存在,当我们选择它时,恢复方案将处理该错误-即从列表中选择一个随机值

Browser('title:=.*Recovery Scenario.*').Page('micclass:=Page')_
    .WebList('name:=testTools').Select 'Rational Robot'
 
MsgBox 'Item Selected: ' & Browser('title:=.*Recovery Scenario.*').Page('micclass:=Page')_
	.WebList('name:=testTools').GetROProperty('value')

当执行上面这段代码时,你会发现不再抛出测试错误而是选中列表中的一个随机值.场景恢复方案被触发并成功执行后将出现下面的结果:

Recovery Scenario Executed

场景恢复执行记录


TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-03  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 15210
  • 日志数: 20
  • 建立时间: 2010-01-27
  • 更新时间: 2014-07-09

RSS订阅

Open Toolbar