当前位置: 首页 > 编程日记 > 正文

转:一个简单的基于WEB的QTP自动化测试框架-SAFFRON

来源:

http://www.itestware.com/ctest/index.php?option=com_content&view=article&id=62:webqtp-saffron&catid=35:testing_is_believing

06年的时候,Mercury 提供了一个QTP自动化测试框架原型 - SAFFRON,可用于指导我们开发基于WEB的自动化测试框架,有时间会仔细分析一下SAFFRON,陆续POST一些研究成果出来。

下面是该框架的源代码:

'************************************************************
' S.A.F.F.R.O.N. Prototype 1.1'
' Simple Automation Framework For Remarkably Obvious Notes
' Copyright © 2006 Mercury Interactive Corporation
'
' Notes:
'
' Requires QuickTest Professional 9.1
'
' Author       : Adam Gensler
' Created      : July 12, 2006
' Last Updated : September 11, 2006
'
' This prototype framework is provided AS IS, and is meant
' to be used for instructional purposes.
'
' This framework is a prototype, and is not supported
' by Mercury Interactive.
'
'************************************************************
initialized = false
thirdlevel = ""
level = ""
desc = ""
object = ""
objectDescription = ""

levelsubdescriptiondelimiter = ","
leveldescdelimiter = "|"
objectdelimiter = "|"
leveldelimiter = "|"
objectsDescriptiondelimiter = "|"

webLevels = "Browser|Page|Frame"
webLevelsDesc = "micclass:=Browser|micclass:=Page|micclass:=Frame|"
' 扩展对Image对象的支持
objects = "Link|WebButton|WebList|WebEdit|Image"
objectsDescription = "micclass:=Link|micclass:=WebButton|micclass:=WebList|micclass:=WebEdit|micclass:=Image"

' Generates a generic description based up on the "level" viarable
' levelstr - will be one of the values that is in the level array
' returns - string representative of the object hierarchy
Public Function GenerateDescription (levelstr)
 l = IndexOf(level, levelstr)
 If l >=0 Then
  fdesc = level(0) & "(" & Quote(desc(0)) & ")."
  If l >= 1 Then
   fdesc = fdesc + level(1) & "(" & Quote(desc(1)) & ")."
   If 2 >= l Then
    If thirdlevel <> "" Then
     fdesc = fdesc + level(2) & "(" & Quote(desc(2)) & "," & Quote("name:=" & thirdlevel) & ")."
    End If
   End If
  End If
 End If
   GenerateDescription = fdesc
End Function

' Generates an object description based upon the object, and objectDescription arrays
' obj - name of the object in the object array
' prop - additional property to help uniquely identify the object
' returns - a string representative of the object description
Public Function GenerateObjectDescription (obj, prop)
 i = IndexOf(object, obj)
 ndesc = ""
   If i <> -1 Then
  ndesc = obj & "(" & Quote(objectDescription(i)) & "," & Quote(prop) & ")."
 End If
 GenerateobjectDescription = ndesc
End Function

' given an array, returns the index of the value to search for
' ary - an array
' str - value to search for in an array
' returns - index in array
Public Function IndexOf (ary, str)
 val = -1
 For i = 0 to UBound(ary)
  If ary(i) = str Then
   val = i
  End If
 Next
 IndexOf = val
End Function

' configures framework to work within the context of a specific frame
' val - the Name of the frame to work within -- use Object Spy if you don't
'       already know the frame name
Public Function WorkInFrame (val)
 Report micPass, "Enter Frame", "Entered scope of frame " & Quote(val)
 thirdlevel = val
End Function

' configures the framework to work outside the context of a specific frame
Public Function StopWorkingInFrame
 Report micPass, "Exit Frame", "Exited scope of frame " & Quote(thirdlevel)
 thirdlevel = ""
End Function

' generates a string with embedded/surrounding quotes
Public Function Quote (txt)
 Quote = chr(34) & txt & chr(34)
End Function

' navigate to a site if the browser is already opened, otherwise run initialization
Public Function BrowseTo (url)
 thirdlevel = ""
 Report micPass, "Navigate to URL", "Navigating to URL: " & Quote(url)
 If initialized Then
  Execute GenerateDescription("Browser") & "Navigate " & Quote(url)
 Else
  Launch "website", url
 End If
 Reporter.Filter = rfDisableAll
End Function

' waits for the web page to finish loading
Public Function AutoSync
    Execute GenerateDescription("Browser") & "Sync"
End Function

' close all opened browsers
Public Function CloseBrowsers
 If Browser("micclass:=Browser").Exist (0) Then
  Browser("micclass:=Browser").Close
 End If
 While Browser("micclass:=Browser", "index:=1").Exist (0)
  Browser("index:=1").Close
 Wend
 If Browser("micclass:=Browser").Exist (0) Then
  Browser("micclass:=Browser").Close
 End If
End Function

' prepares the framework for usage, and configures all internal framework
' variables and structures
' apptype - used to launch different types of applications based
'           upon different technologies -- currently there is only web
' val     - string that represents what to launch
' returns - always returns true
Public Function Launch (apptype, val)
 If "website" = apptype Then
  thirdlevel = ""
  Report micPass, "Initialize", "Initializing Framework"
  level = split(webLevels, leveldelimiter, -1, 1)
  desc = split(webLevelsDesc, leveldescdelimiter, -1, 1)
  object = split(objects, objectdelimiter, -1, 1)
  objectDescription = split(objectsDescription, objectsDescriptiondelimiter, -1, 1)
  CloseBrowsers
  Set IE = CreateObject("InternetExplorer.Application")
  IE.visible = true
  IE.Navigate val
  While IE.Busy
   wait 1
  Wend
 End If
 initialized = true
 Launch = true
End Function

' Verify the Existence of an object
' objtype - values should be limited to values in the object array
' text    - multi-purpose argument that indicates what to verify
'         - for a link, or button, it's the text of the control
'         - for a list, it's the name of the control
'         - for a frame, it's the name of the frame
Public Function Verify (objtype, text)
   rval = false
 localDesc = ""
 estr = ""
 If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
 Else
  localDesc = GenerateDescription(level(1))
 End If

AutoSync()

Select Case objtype
 Case "Page"
  Execute "rval = " & GenerateDescription(level(1)) & "Exist (0)"
  If rval Then
   Execute "title = " & GenerateDescription(level(1)) & "GetROProperty(" & Quote("title") & ")"
   If title = text Then
    rval = true
   Else
    rval = false
   End If
  End If
 Case "CurrentFrame"
  If thirdlevel <> "" Then
   estr = "rval = " & localDesc
  End If
 Case "Link"
  estr =  "rval = " & localDesc & GenerateObjectDescription("Link", "innertext:=" & text)
 Case "WebButton"
  estr = "rval = " & localDesc & GenerateObjectDescription("WebButton", "value:=" & text)
 Case "WebList"
  estr = "rval = " & localDesc & GenerateObjectDescription("WebList", "name:=" & text)
 Case "WebEdit"
  estr = "rval = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & text)
 End Select

If estr <> "" Then
  Execute estr + "Exist (0)"
 End If

If rval Then
  Report micPass, objtype & " Verification", "The " & objtype & " " & Quote(text) & " was verified to exist"
 Else
  Report micFail, objtype & "  Verification", "The " & objtype & " " & Quote(text) & " was not found"
 End If

If "True" = rval Then
  rval = True
 Else
  rval = False
 End If

Verify = rval
End Function

' Activates an object based upon its object type
' objtype - the type of object should be limited to values in the object array
' text    - identifying text for the control - for a link, it's the text of the link
Public Function Activate (objtype, text)
 localDesc = ""
 If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
 Else
  localDesc = GenerateDescription(level(1))
 End If

AutoSync()

Select Case objtype
 Case  "Link"
  Execute localDesc & GenerateObjectDescription("Link","innertext:=" & text) & "Click"
  Report micPass, "Link Activation", "The Link " & Quote(text) & " was clicked."
 Case "WebButton"
  Execute localDesc & GenerateObjectDescription("WebButton", "value:=" & text) & "Click"
  Report micPass, "WebButton Activation", "The WebButton " & Quote(text) & " was clicked."
 ' 扩展对Image类型的按钮的支持
 Case "Image"
  Execute localDesc & GenerateObjectDescription("Image", "alt:=" & text) & "Click"
  Report micPass, "ImageButton Activation", "The ImageButton " & Quote(text) & " was clicked."
 End Select
End Function

' Selects a specific value from a listbox, or combobox
' objname - name of the control -- use Object Spy if you don't know the name property
' text    - the item in the combobox to select
Public Function SelectFromList (objname, text)
 localDesc = ""
 rv = ""
 rval = false
 If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
 Else
  localDesc = GenerateDescription(level(1))
 End If

AutoSync()

localDesc = localdesc & GenerateObjectDescription("WebList", "name:=" & objname)

Execute "cnt = " & localDesc & "GetROProperty(" & Quote("items count") & ")"
 For i = 1 to cnt
  Execute "rv = " & localDesc & "GetItem (" & i & ")"
  If rv = text Then
   rval = true
  End If
 Next

If rval Then
  Execute localDesc & "Select " & Quote(text)
 End If
 If rval Then
  Report micPass, "WebList Selection", "The WebList item " & Quote(text) & " was selected."
 Else
  Report micFail, "WebList Selection", "The WebList item " & Quote(text) & " was NOT found."
 End If

SelectFromList = rval
End Function

' Enters text into an edit field
' objname - name of the control -- use Object Spy if you don't know what it is
' text    - the text to enter into the control
Public Function EnterTextIn (objname, text)
 localDesc = ""
 rval = true
 If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
 Else
  localDesc = GenerateDescription(level(1))
 End If

AutoSync()

localDesc = localdesc & GenerateObjectDescription("WebEdit", "name:=" & objname)
 Execute localDesc & "Set (" & Quote(text) & ")"
 Report micPass, "Enter Text", "Text: " & Quote(text) & " was entered into " & Quote(objname)
 EnterTextIn = rval 
End Function

' Obtains text from a control
' objtype - is the type of control the get the text from
' objname - is the name of the control -- use Object Spy if you don't know the name
' returns - the text of the control
Public Function GetTextFrom (objtype, objname)
 text = ""
 localDesc = ""
 If thirdlevel <> "" Then
  localDesc = GenerateDescription(level(2))
 Else
  localDesc = GenerateDescription(level(1))
 End If

AutoSync()

Select Case objtype
  Case "WebEdit"
   Execute "text = " & localDesc & GenerateObjectDescription("WebEdit", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
  Case "WebList"
   Execute "text = " & localDesc & GenerateObjectDescription("WebList", "name:=" & objname) & "GetROProperty (" & Quote("value") & ")"
 End Select
 Report micPass, "Capture Text", "Text: " & Quote(text) & " was captured from the control " & Quote(objname)
 GetTextFrom = text
End Function

' Wrapper for the Reporter.Report Event method
' - could be used to create custom reports more easily
' See Reporter.ReportEvent documentation for usage
Public Function Report (status, objtype, text)
 Reporter.Filter = rtEnableAll
 Reporter.ReportEvent status, objtype, text
 Reporter.Filter = rfDisableAll
End Function

转载于:https://www.cnblogs.com/vinyfeng/articles/1338471.html

相关文章:

积极学习的朋友

自从去年7月反省之后&#xff0c;认识的朋友逐渐多了&#xff0c;天下那么大&#xff0c;优秀的人很多&#xff0c;通过网络认识是一个很不错的途径&#xff0c;经过一段时间后&#xff0c;圈子范围扩大了很多&#xff0c;行业上和非行业上都有涉及&#xff0c;对自己认知冲击很…

hive向表格中插入数据并分析语句

1&#xff0c;---导入mds_imei_month_info set hive.exec.max.dynamic.partitions 100000; //最大的动态分区表 set hive.support.concurrencyfalse; //是否支持并发 set hive.exec.max.dynamic.partitions.pernode 100000; //each mapper or reducer可以创建的最大动态分区数 …

资源与工具下载

Red Hat Linux镜像文件 链接&#xff1a;https://pan.baidu.com/s/1N3Khh6pyKpMkOnkEL-U9_A 提取码&#xff1a;0hnu jdk1.8(32位64位)安装版 链接&#xff1a;https://pan.baidu.com/s/15Jm6Ca6IBR3OEauge-4FYQ 提取码&#xff1a;uo2l Tomcat 8(32位64位)安装版 链接…

Global.asax中Application_Error无法执行

Global.asax中Application_Error无法执行问题解决后才发现这句是错误的&#xff0c;之前用VS2005开发后发布到服务器上也出现这种情况&#xff0c;后来莫名 的好了(是解决了没发现原因)。之前的文章链接后来用catch捕捉后真相大白&#xff0c;System.Security.SecurityExceptio…

虚拟化如何做实?详解戴尔2.0版解决方案

继5月份推出虚拟化解决方案后&#xff0c;2008年9月16日&#xff0c;戴尔又宣布推出包括新款服务器、存储产品&#xff0c;管理工具及基础设施咨询服务在内的全新虚拟化2.0解决方案&#xff0c;致力于为客户提供通向虚拟化的智慧之道。戴尔的虚拟化解决方案包括哪些具体的内容&…

Socket/ServerSocket 选项

Socket/ServerSocket 选项 原文:Socket/ServerSocket 选项在网络编程中&#xff0c;Socket/ServerSocket有一些选项用来自定义一些行为&#xff0c;现在分享一下。Socket选项 1.TCP_NODELAY 在Socket发送数据时&#xff0c;默认情况下&#xff0c;数据会先进入缓冲区&#xff0…

MySQL主从复制的常用拓扑结构

1、复制的常用拓扑结构 复制的体系结构有以下一些基本原则&#xff1a; (1) 每个slave只能有一个master&#xff1b; (2) 每个slave只能有一个唯一的服务器ID&#xff1b; (3) 每个master可以有很多slave&#xff1b; (4) 如果你设置log_slave_updates&#xff0c;…

统计java文件中的代码行数

统计Java代码行数工具类 —— CodeCounterUtil.java 统计指定目录下的java文件中代码行数 —— public static int getCodeNumFromFolder(String filePath)统计具体文件中的java代码行数 —— public static int getCodeNumFromFile(String filePath)import java.io.Buf…

jQuery插件thickbox在ie下垂直居中问题

jQuery 插件 thickbox 3.1 在ie下总不能垂直居中&#xff0c;按“http://jamazon.co.uk/web/2008/03/17/thickbox-31-ie7-positioning-bug/”上的方法改了也没用&#xff0c;咋办&#xff1f; 我是这样改的&#xff1a;管它ie6还是ie789&#xff0c;一视同仁&#xff01; 原284…

dos分区:C语言建立多个PRI DOS分区

dos分区:C语言建立多个PRI DOS分区 来源: 发布时间:星期四, 2008年9月25日 浏览:127次 评论:0一、引言 在DOS系统下&#xff0c;在计算机应用培训中因培训要求不同&#xff0c; 对软件的要求也不同&#xff0c;由于学员的误操作&#xff0c;存放在硬盘上的软件和重要数据容 易被…

简单几步让CentOS系统时间同步

在使用CentOS系统的时候&#xff0c;我们可能会遇到时间不准的问题&#xff0c;那我们如何解决这个我问题呢&#xff0c;下面就来教大家一个CentOS系统时间同步的方法&#xff0c;希望大家可以解决自己所存在的疑问。 CentOS系统时间同步的步骤如下&#xff1a; 新装的CentOS系…

挨踢人生路--记我的10年18家工作经历 - 后记

挨踢人生路--记我的10年18家工作经历 &#xff0d; 前言挨踢人生路--记我的10年18家工作经历 &#xff0d; 从大学说起――不得不说的一些事情挨踢人生路--记我的10年18家工作经历 &#xff0d; 第1家公司&#xff0c;在老家的工作挨踢人生路--记我的10年18家工作经历 &#xf…

FileUtil

文件工具类 —— FileUtil.java 获取Web工程的根目录 —— String getBasePath()方法获取文件名称 —— public static String getFileName(String filePath)方法获取文件名称前缀 —— public static String getPrefixOfFileName(String filePath)方法获取文件名后缀(…

C# Sato CL4NX打印机发送SBPL指令打印表面信息、RFID芯片数据写入

待更新..转载于:https://www.cnblogs.com/zh7791/p/7650073.html

同步SQL Server 2000 数据库

为什么要同步SQL Server 2000 数据库&#xff0c;它都用在什么场合 数据实时备份同步&#xff0c;数据库服务器出问题时我们也有其正常工作时的备份 数据实时备份同步&#xff0c;一台服务器负载不起时&#xff0c;可以用来做负载均衡 数据实时备份同步&#xff0c;数据库服务器…

【Leecode】两数相加

学习了链表结构&#xff0c;链表中元素的访问&#xff0c;对象指针的初始化与赋值&#xff0c;链表的创建&#xff08;多个节点链接起来&#xff09;&#xff0c;进位计算的表达。 100ms /*** Definition for singly-linked list.* struct ListNode {* int val;* ListN…

推荐一个HTML的语法高亮解析器

http://code.google.com/p/syntaxhighlighter/wiki/Languages支持高亮的语法如下Language Aliases C cpp, c, c C# c#, c-sharp, csharp CSS css Delphi delphi, pascal Java java Java Script js, jscript, javascript PHP php Python py, python Ruby rb, ruby, rails, ror S…

angularJS中directive与controller之间的通信

当我们在angularJS中自定义了directive之后需要和controller进行通讯的时候&#xff0c;是怎么样进行通讯呢&#xff1f; 这里介绍3种angular自定义directive与controller通信的指令。 1.指令作用域中的"" 作用&#xff1a;把当前属性作为字符串传递实现指令与html页…

Eclipse启动失败:No java virtual machine was found after searching the follwing locations

Eclipse启动失败&#xff0c;错误信息如下如所示&#xff1a; 通过阅读错误信息&#xff0c;可以看到错误原因和 javaw.exe路径 有关&#xff1b; 打开eclipse.ini文件&#xff0c;也就是启动Eclipse的初始化文件&#xff1a; 在本地计算机中找到jdk安装路径下javaw.exe文件&a…

Cisco路由器安全配置必用10条命令

当谈到配置一台新的cisco路由器&#xff0c;多数配置依赖于路由器的类型以及它将服务的用途。然而&#xff0c;每位管理员都有其自己的“正确”配置每台路由器的命令列表。笔者将和你分享他自己配置路由器的十条命令列表。<?xml:namespace prefix o ns "urn:schemas…

Tensorflow学习教程------模型参数和网络结构保存且载入,输入一张手写数字图片判断是几...

首先是模型参数和网络结构的保存 #coding:utf-8 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_datamnist input_data.read_data_sets(MNIST_data,one_hotTrue) #每个批次的大小 batch_size 100 n_batch mnist.train._num_examples // ba…

IntelliJ IDEA乱码问题解决方法

目录 1、设置文件编码 2、设置控制台编码 3、设置Tomcat Server编码 4、修改配置文件编码内容 1、设置文件编码 第1步&#xff1a;打开IDEA&#xff0c;依次点击File、Settings... 打开Setting窗口&#xff1b; 第2步&#xff1a;在Settings窗口中&#xff0c;依次点击Ed…

Windows 7的CMD中 Telnet 无法执行的解决办法

在Windows 7的CMD中&#xff0c;执行telnet 192.168.1.10 80 会提示没有这个命令的提示&#xff0c;这是因为Win7默认是没有安装Telnet的&#xff08;在以往的WINDOWS系统中都是默认安装的&#xff09;。解决办法&#xff1a;在Win7中&#xff0c;进入控制面板&#xff0c;然后…

Qt——模态、非模态

模态&#xff1a; 只能操作对话框非模态&#xff1a;要使用 QDialog *_d new QDialog();_d->setattribute(Qt::WA_DeleteOnClose);_d->show();转载于:https://www.cnblogs.com/yangxinrui/p/10515249.html

c# 取两个时间的间隔

c#可以取两个时间的年月日时分秒之间的间隔&#xff0c;不受跨年月的影响。声明一个 TimeSpan System.TimeSpan ts dtNightEnd.Subtract(dtAmStart); dtNightEnd是原始时间 减去 dtAmStart 这个时间 获得一个TimeSpan TimeSpan 自带了间隔属性 ts.Days.ToString(); ts.Hours.…

MySQL数据表命令

显示表的相关信息&#xff1a; show table status like "表名"&#xff1b; show table status like "表名" \G 格式化&#xff0c;以记录条目形式显示&#xff0c;更清晰 注意&#xff1a;\G后面不能加分号&#xff0c;不然会出现查询错误。因为\G在…

undefined reference to 'pthread_create'问题解决(转)

undefined reference to pthread_createundefined reference to pthread_join问题原因&#xff1a;pthread 库不是 Linux 系统默认的库&#xff0c;连接时需要使用静态库 libpthread.a&#xff0c;所以在使用pthread_create()创建线程&#xff0c;以及调用 pthread_atfork()函数…

C语言程序设计第一次作业

&#xff08;一&#xff09;实验总结 1.圆的面积和周长问题 &#xff08;1&#xff09;题目&#xff1a; 输入圆的半径&#xff0c;计算圆的周长和面积。 &#xff08;2&#xff09;流程图 &#xff08;3&#xff09;测试数据及运行结果 &#xff08;4&#xff09;实验分析 问题…

U盘中毒,无法删除System Volume Information文件夹

情景&#xff1a;U盘中毒&#xff0c;U盘内的文件夹名称变成.exe后缀&#xff0c;且多出一个名为System Volume Information的文件夹&#xff0c;对U盘进行格式化后&#xff0c;所有文件消失&#xff0c;当拔出U盘&#xff0c;再次插入电脑时&#xff0c;发现System Volume Inf…

用Javascript修正12个常见的浏览器问题

我们提倡尽可能使用CSS&#xff0c;而且我们常常能做到这一点。现代浏览器有很好的CSS支持-这无疑足够好让你使用CSS来控制布局和版面设计。但是有时候&#xff0c;某些网页元素在不同的浏览器会出现不同。 如果你不知道原因&#xff0c;不要过于担心&#xff0c;请研究CSS规则…