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 ...
随机推荐
- Codeforces - 1189B - Number Circle - 贪心
https://codeforc.es/contest/1189/problem/B 优先考虑最大的元素怎么构造.拿两个次大的围着他就很好,但是其他的怎么安排呢?就直接降序排列就可以了. a数组还开错 ...
- Java 小技巧和在Java避免NullPonintException的最佳方法(翻译)
前几天就g+里面看到有人引用这篇博文.看了一下.受益颇多. 所以翻译过来,希望和大家一起学习.本人英语水平有限,假设有错,请大家指正. 原文地址(须要翻墙):http://ja ...
- Android手机、电视(盒子) 打开ADB调试 一览表
手机.电视(盒子) 打开ADB调试 一览表 一.手机打开ADB调试方法 序号 名称 描述 方式 1 华为手机 EMUI 1.设置 ->关于手机-> 版本号 点击(4~5次)2.返回设置 - ...
- eclipse 设置注释模板
window->preference->java->code styple->code template->Comments Types /** * @author $ ...
- A星寻路
逻辑代码 using System.Collections.Generic; using System.Text; using UnityEngine; namespace Game { public ...
- windows下搭建Mongo主(Master)/从(slave)数据库同步
需要启动两个mongoDb文档数据库,一个是主模式启动,另一个是属于从模式启动. 1. 创建主从服务器 主服务器:192.168.1.131:27017 备服务器:192.168.1.131:2701 ...
- mysql查找表名
SELECT *FROM information_schema.TABLESWHERE 1=1 AND table_name LIKE '%order%' AND table_comment like ...
- JavaWeb(三):JSP
JSP是JavaServer Page的缩写,也就是服务端网页. 一.概述 1.1 为什么使用JSP 在很多动态网页中,绝大部分内容都是固定不变的,只有局部内容需要动态产生和改变.JSP是简化Serv ...
- Struts2基础-4 -struts拦截器
Struts2拦截器工作原理 拦截器围绕着 Action和 Result的执行而执行. Struts2拦截器的工作方式如图10.2所示.从上图中可以看出, Struts2拦截器的实现原理和 Servl ...
- centos6.8下安装nginx
我用的阿里云上的镜像,make的时候总是出错,后来说是gcc安装不完整,要重新用下面命令安装 下: yum install gcc gcc-c++ gcc-g77 接下来下载nginx用到的一些库 w ...