zoukankan      html  css  js  c++  java
  • QTP 场景恢复– 函数调用

      创建自动化测试是为了实现无人值守下运行,但也给开发人员带来一些问题。假如你离开办公室前启动测试,想要让它通宵运行。然而,由于不可预见错误测试在某一停止中断了测试结果。因此QTP中引入场景恢复方案。测试运行错误"列表菜单中到选项",可参考以下场景恢复方案

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

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

    Function Recovery_ListItemIsNotFound(Object, Method, Arguments, retVal)
         Dim sAllItems, arrAllItems, intItem
     
         With Object
              'Retrieve all items from the Listbox
              sAllItems = .GetROProperty("all items")
              'Split 'all items' using a delimiter ";" into an array
              arrAllItems = Split(sAllItems, ";")
     
              'Select a random number
              intItem = RandomNumber.Value(LBound(arrAllItems), UBound(arrAllItems))
              .Select "#" & intItem
     
              Reporter.ReportEvent micInfo, "ListItemIsNotFound", "Item: " & .GetROProperty("value")
         End With
    End Function 

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

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

     Recovery Scenario Wizard

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

    Recovery Scenario Wizard - Welcome

    场景恢复向导 - 欢迎界面

     当上面的界面打开后: 

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

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

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

      6. 选择 Function Call ,点击 Next

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

        Define New Function

        定义新函数

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

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

      12. 给场景命名,Click Next

      13. 最后, 检查选项: 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

    场景恢复执行记录

    此外,还有很多其他场景,我会不断整理补充一些重要场景. 

    翻译自http://relevantcodes.com/recovery-scenario-test-run-error-item-in-list-or-menu-not-found/ ,若有错误部分,大家积极留言共同纠正

  • 相关阅读:
    树链剖分-bzoj1036
    POJ3489企鹅
    51nod 1130
    51nod-8-16
    51nod-8-15
    51nod 8-14
    51nod1582-n叉树
    51nod1574排列转换
    51nod1785数据流中的算法
    iOS开发--Swift 最近项目开发中遇到的一些小问题与解决方法
  • 原文地址:https://www.cnblogs.com/sylvia-liu/p/3716776.html
Copyright © 2011-2022 走看看