QTP使用dictionary 对象
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 对象的更多相关文章
- VBS基础篇 - Dictionary对象
Dictionary是存储数据键和项目对的对象,其主要属性有Count.Item.Key,主要方法有Add.Exists.Items.Keys.Remove.RemoveAll. '建立字典 Dim ...
- VB中的Dictionary对象
VB中的Dictionary对象 Dictionary对象不是VBA或Visual Basic实时语言的具体存在的部分,它是存在于Microsoft Scripting Runtime Library ...
- 存储数据键和项目对的类(Dictionary对象)
存储数据键和项目对的类(Dictionary对象) <% Class Dictionary Public Copyright, Developer, Name, Version, Web Pri ...
- Dictionary 对象
Dictionary 对象 对象的存储数据键/项对. 语法 Scripting.Dictionary 说明 Dictionary对象相当于 PERL 关联数组. 项目,可以是任何形式的数据,存储在数组 ...
- WebAPI接口返回ArrayList包含Dictionary对象正确解析
一.问题提出 为了减少流量,将key-value(键值对)直接输出到Dictionary<string, string>,接口返回结果如下: 其中{}里面内容如下: 上图显示600是键,4 ...
- 使用QTP测试Web对象
加载Web插件先启动QTP,再启动浏览器,否则Web元素识别不了最新版本QTP11支持的浏览器:IE:6.7.8Firefox:3.0.x.3.5.QTP支持直接访问DOM(Document Obje ...
- [转载]使用QTP测试Windows对象
Desktop对象的使用: 通过Desktop对象,可以访问Windows的桌面顶层对象.Desktop对象包括CaptureBitmap.ChildObjects.RunAnalog方法. (1) ...
- QTP设置共享对象库
第一步:把需要加到共享对象库中的各个用例脚本的对象库,分别导出成.tsr文件. 操作方法:先用QTP打开已经录制完毕的脚本后,选择Resources-->Object Repository.然后 ...
- QTP VBScript RegExp对象的运用
下面来讲讲RegExp对象: Vbs提供了针对正则表达式的一个非常实用的类,就是RegExp Global属性:代表全局匹配 IgnoreCase属性:大小写忽略 Pattern属性:正则表达式 Ex ...
随机推荐
- 字符串类——KMP算法的应用
1,字符串类中的新功能(本文代码已集成到字符串类——字符串类的创建(上)中,这里讲述函数实现原理): 2,子串查找(KMP 算法直接运用): 1,int indexOf(const char* s) ...
- 【Linux】php7.2.8 + xdebug + composer + php代码覆盖率 + jenkins配置 (实操记录,亲测可用)
[一.linux安装php 7.2.8] 1.wget http://nginx.org/download/nginx-1.9.9.tar.gz # nginx可不安 ...
- 分页插件 Bootstrap Paginator
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态 ...
- CentOS7.6系统安装zabbix3.4.8客户端
一. 准备安装包 将本地的zabbix-3.4.8软件包上传至服务器, 二. 安装依赖包 安装依赖包:yum install gcc* pcre* psmisc -y 三. 安 ...
- vue下超级滚动条perfect-scrollbar(在特定框架里使用一款并非为该框架定制的库/插件)
点我查看
- Linux就该这么学11学习笔记
参考链接:https://i.cnblogs.com/EditPosts.aspx?opt=1 文件传输协议 一般来讲,人们将计算机联网的首要目的就是获取资料,而文件传输是一种非常重要的获取资料的方式 ...
- MySQL--18 报错总结
报错1: 报错原因:MySQL的socket文件目录不存在. 解决方法: 创建MySQL的socket文件目录 mkdir /application/mysql-5.6.38/tmp 报错2: 报错原 ...
- Jenkins ant打包部署
选择项目 自由风格
- 【串线篇】spring boot配置文件大全【下】
一.配置文件占位符 1.1.随机数 ${random.value}.${random.int}.${random.long} ${random.int(10)}.${random.int[1024,6 ...
- js 弹窗并定时关闭
1. $('input').click(function() { prompt('点击成功', 2000) }) function prompt(newName, time, fn) { var $d ...