1. 创建即使用Dictionary对象

' 创建Dictionary对象
Set Dic = CreateObject("Scripting.Dictionary")
' 添加Dictionary的key和value
For Iterator = 1 To 3 Step 1
 Dic.Add CStr(Iterator),Iterator & "_Value"
Next
' 循环读取Dictionary的key和value
For Iterator = 1 To Dic.Count Step 1
 Msgbox  Dic.Item(CStr(Iterator))
Next

DicArray = Dic.Items
'For I = 0 To Dic.Count
For I = 0 To UBound(DicArray)
 Msgbox DicArray(I)
Next

' 判断是否存在某个Key,如果存在,则把其去掉
If Dic.Exists("2") Then
 Msgbox Dic.Item("2")
 Dic.Remove("2")
End If
Msgbox Dic.Count
' 清空所有 Key和Value
Dic.RemoveAll()
Msgbox Dic.Count

2. 把Dictionary添加到注册表中QTP的保留对象

Dictionary对象经常用来存储对象 ,把Dictionary添加到注册表中QTP的保留对象 ,则可以用于替代QTP的环境变量(Environment),在Action之间共享数据 。

下面的脚本摘自QTP的CodeSamplesPlus并做了点修改,添加了点注释:

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'As an alternative to using environment variables to share values between actions 
' you can use the Dictionary object.    
'The Dictionary object enables you to assign values to variables that are accessible from all actions (local and external) 
'called in the test in which the Dictionary object is created. 
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

' 把Dictionary添加到注册表,这样可以在使用GlobalDictionary时有Intelisence智能感应提示
'in order to have intelisence for the Dictionary object, and have it recognized by other actions, it is added to the registry
Dim WshShell
Set WshShell =CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU/Software/Mercury Interactive/QuickTest Professional/MicTest/ReservedObjects/GlobalDictionary/ProgID", "Scripting.Dictionary","REG_SZ"
Set WshShell = Nothing

'clearing the Keys if they exist in the object    清空Dictionary中的项
If  GlobalDictionary.Exists("AgentName") Then
    GlobalDictionary.Remove("AgentName")
End If
If  GlobalDictionary.Exists("Password") Then
    GlobalDictionary.Remove("Password")
End If
If  GlobalDictionary.Exists("OrderNumber") Then
    GlobalDictionary.Remove("OrderNumber")
End If

'add 3 keys to the Dictionary object    添加项
GlobalDictionary.Add "AgentName", "Mercury"
GlobalDictionary.Add "Password","Mercury" 
GlobalDictionary.Add "OrderNumber", 0

' 使用GlobalDictionary中的数据
'login to Mercury Flight application using the Dictionary objects we just defined.
Dialog("Login").WinEdit("Agent Name:").Set  GlobalDictionary.Item("AgentName")
Dialog("Login").WinEdit("Agent Name:").Type  micTab
Dialog("Login").WinEdit("Password:").SetSecure GlobalDictionary.Item("Password")
Dialog("Login").WinButton("OK").Click

'inserting an order in the flight application
Window("Flight Reservation").WinObject("Date of Flight:").Type "111111"
Window("Flight Reservation").WinComboBox("Fly From:").Select "Denver"
Window("Flight Reservation").WinComboBox("Fly To:").Select "Frankfurt"
Window("Flight Reservation").WinButton("FLIGHT").Click
Window("Flight Reservation").Dialog("Flights Table").WinButton("OK").Click
Window("Flight Reservation").WinEdit("Name:").Set "6"
Window("Flight Reservation").WinRadioButton("Business").Set
Window("Flight Reservation").WinButton("Insert Order").Click
'Window("Flight Reservation").ActiveX("Threed Panel Control").WaitProperty "text", "Insert Done...", 10000
Window("Flight Reservation").WinObject("AfxWnd40").WaitProperty "text", "Insert Done...", 10000

'saving the Order number in the Datatable, and then saving it in a dictionary item
Window("Flight Reservation").WinEdit("Order No:").Output CheckPoint("Order No:")
GlobalDictionary.Item("OrderNumber") = datatable.Value ("Order_No_text_out",dtGlobalSheet)

'closing the application
Window("Flight Reservation").Close

'reports to the report all the Keys & items found in the dictionary object
For i=0 to GlobalDictionary.Count-1
    KeysArray = GlobalDictionary.keys
    ItemsArray = GlobalDictionary.Items
    reporter.ReportEvent Done,"Reporting Dictionary Item Number : " & i ,  "Key : " & KeysArray(i) & " , Item : " & ItemsArray(i)
Next

' 调用Action2

RunAction "Action2", oneIteration

Action2的代码:

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' This code segment also exists in the main Action.
' in this reusable action, the value are avaiable ONLY  when they are called from Test "Dictionary"
' calling this action as a stand alone, will result in an error since those Keys & values won't be valid.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' GlobalDictionary中的数据可以跨Action使用
'reports to the report all the Keys & items found in the dictionary object
For i=0 to GlobalDictionary.Count-1
    KeysArray = GlobalDictionary.keys
    ItemsArray = GlobalDictionary.Items
    reporter.ReportEvent Done,"Reporting Dictionary Item Number : " & i ,  "Key : " & KeysArray(i) & " , Item : " & ItemsArray(i)
Next

QTP使用dictionary 对象的更多相关文章

  1. VBS基础篇 - Dictionary对象

    Dictionary是存储数据键和项目对的对象,其主要属性有Count.Item.Key,主要方法有Add.Exists.Items.Keys.Remove.RemoveAll. '建立字典 Dim ...

  2. VB中的Dictionary对象

    VB中的Dictionary对象 Dictionary对象不是VBA或Visual Basic实时语言的具体存在的部分,它是存在于Microsoft Scripting Runtime Library ...

  3. 存储数据键和项目对的类(Dictionary对象)

    存储数据键和项目对的类(Dictionary对象) <% Class Dictionary Public Copyright, Developer, Name, Version, Web Pri ...

  4. Dictionary 对象

    Dictionary 对象 对象的存储数据键/项对. 语法 Scripting.Dictionary 说明 Dictionary对象相当于 PERL 关联数组. 项目,可以是任何形式的数据,存储在数组 ...

  5. WebAPI接口返回ArrayList包含Dictionary对象正确解析

    一.问题提出 为了减少流量,将key-value(键值对)直接输出到Dictionary<string, string>,接口返回结果如下: 其中{}里面内容如下: 上图显示600是键,4 ...

  6. 使用QTP测试Web对象

    加载Web插件先启动QTP,再启动浏览器,否则Web元素识别不了最新版本QTP11支持的浏览器:IE:6.7.8Firefox:3.0.x.3.5.QTP支持直接访问DOM(Document Obje ...

  7. [转载]使用QTP测试Windows对象

    Desktop对象的使用: 通过Desktop对象,可以访问Windows的桌面顶层对象.Desktop对象包括CaptureBitmap.ChildObjects.RunAnalog方法. (1)  ...

  8. QTP设置共享对象库

    第一步:把需要加到共享对象库中的各个用例脚本的对象库,分别导出成.tsr文件. 操作方法:先用QTP打开已经录制完毕的脚本后,选择Resources-->Object Repository.然后 ...

  9. QTP VBScript RegExp对象的运用

    下面来讲讲RegExp对象: Vbs提供了针对正则表达式的一个非常实用的类,就是RegExp Global属性:代表全局匹配 IgnoreCase属性:大小写忽略 Pattern属性:正则表达式 Ex ...

随机推荐

  1. [POJ3612] Telephone Wire(暴力dp+剪枝)

    [POJ3612] Telephone Wire(暴力dp+剪枝) 题面 有N根电线杆,初始高度为h[i],要给相邻的两根连线.可以选择拔高其中一部分电线杆,把一根电线杆拔高\(\Delta H\)的 ...

  2. linux mysql修改数据表结构语法

    MySQL修改表的语法=========================增加列[add 列名]=========================①alter table 表名 add 列名 列类型 列 ...

  3. P4843 清理雪道(上下界网络流)

    P4843 清理雪道 上下界最小流 我们先搞一遍上下界可行流(转) 回忆上下界最大流的写法:在可行流的残量网络$s\ -\ t$上跑最大流,答案为可行流$+$残量网络的最大流 那么上下界最小流的写法呢 ...

  4. java Activiti6.0 后台 框架 spring5 SSM 工作流引擎 审批流程

    1.模型管理 :web在线流程设计器.预览流程xml.导出xml.部署流程 2.流程管理 :导入导出流程资源文件.查看流程图.根据流程实例反射出流程模型.激活挂起 3.运行中流程:查看流程信息.当前任 ...

  5. Kintex7 XC7K325T 板卡五兄弟

    Kintex 7五兄弟 1.     基KC705E 增强版基于FMC接口的Xilinx Kintex-7 FPGA K7 XC7K325T PCIeX8 接口卡(136) 本板卡是Xilinx公司芯 ...

  6. 11-基于CPCI的中频功率放大收发板

    1.板卡参数介绍 无线输入口 无线发射口 1M~3GHZ,可调,步进100HZ(非跳频模式) 功率:≤﹢10±2.5 dBm 收发通道数 收发各1通道/板 中频输入输出 70MHz, 5MHz/30M ...

  7. 毕设问题(1)表格table的表头自定义、复合表头,组合表格

    毕业设计,是一个web项目,遇到的些问题,记录下来.也许也有同样只知道一些,不是那么系统的学过的人,会遇到同样的问题,希望有所帮助. 百度知道有这样一个问题: bootstrap table 如何实现 ...

  8. weblogic启动脚本

    DATE=`date +%Y%m%d%H%M%S` user=`whoami` logDir=/app/logs/sguap_admin #启动日志存放路径sguap是例子系统简称# logDestd ...

  9. 在Linux服务器上运行jar包,并且使jar包一直处于后台执行

    1.我jar包在linux的目录为/a/bbb.jar         正常情况下,使用在/a目录下使用  java -jar bbb.jar 可以直接运行该jar包的项目,运行成功之后使用crtl+ ...

  10. 手写Mybatis,还需要后面调整下

    参考博客 https://blog.csdn.net/Kurozaki_Kun/article/details/81482212 个人理解 读取Mybatis配置文件 数据库连接信息 读取Mapper ...