QTP笔记

参考:

小强老师零基础学习软件测试系列视频教程之QTP学习指南

《自动化软件测试》

QTP自动化测试实践》

QTP helpsamples, GeneralHelp.chm, VBScript56.CHM

慢慢学习VBScript(V1.0).pdf

 

File menu

²             Process guidance managementView > process guidance, automation > process guidance list 过程指南,默认安装会包括以下几个过程指南:
1Keyword-Driven Testing:介绍和指引QTP用户熟悉关键字驱动(Keyword-Driven)的测试方法和测试过程。Table-driven testing实现KDT主要依赖自动化框架,通过框架仅需测试人员开发表格和关键字,框架通过解释表格数据和关键字执行脚本。
2Application Areas:介绍和指引QTP用户熟悉应用程序区域(Application Areas)的概念和使用方法。
3Business Components:介绍和指引QTP用户熟悉业务组件(Business Components)的概念和使用方法。

²             File > Settings,也可以在运行过程中设置和获取测试选项,如

settting(“DefaultTimeOut”) QTP用于查找对象的最大时间

Setting.Item通过Item属性获取和设置脚本的全局信息,如

With setting

       If Not .Exists(“ItemNumber”) then

              .Add “ItemNumber”, 1

       Else

              .Item(“ItemNumber”) = .Item(“ItemNumber”) + 1

              End if

       End with

       Item属性在整个测试项目的各次运行之间有效,即下一次脚本运行能保持上一次运行的值,而环境变量是固定值,仅在测试脚本运行中可以读取和更改。

²             File > Settings > Local system monitor: QTP Help > LocalSystemMonitorDemo.exe。勾上“Enable local system monitoring ..”,加上需要监控的本机系统性能指标,运行结束后可以在resultssystem monitor页面看到结果。

Edit, View, Automation, Debug menu

²             录制方式:

n         normal recording 通过识别UI对象

n         Analog recording: 记录操作路径,以鼠标轨迹为基础,脚本不能修改

n         Low level recording: 以对象坐标为基础,录制对象为window, winobject

²             Tools>Check Syntax (Ctrl+F7), View > Information, View > Debug Viewer

²             Complete word ctrl + 空格将自动匹配关键字或函数, F3 Record, F4 Stop, F5 Run, F9 Insert/Remove breakpoint, F10 step over, F11 Step into, shift + F11 step out

²             QTP help > MaintenanceMode.exe: Automation > Maintenance Run Mode  当程序界面上的对象改变,导致运行原来录制的脚本时出现对象找不到的情况,这时就可以用maintenance run mode,当出现错误时会出现maintenance run wizard帮助定位和更新对象。

²             Automation>Update Run Mode: When you run a test in Update Run Mode, QuickTest runs the test to update the test object descriptions, the Active Screen images and values, and/or the expected checkpoint values. After you save the test, the updated data is used for subsequent runs. After using Update Run Mode to update the test, you may want to use the Update from Local Repository option in the Object Repository Manager to merge the objects from the local repository back to a shared object repository.

Insert menu:

²             事务 transaction,在以下情况使用:

n         LR只调用QTP startend transaction之间的代码段

n         统计某操作所需的时间

²             验证点:

n         文字类型验证点可使用正则表达式自定义搜索条件 . * ^ []

验证点类型

概述

用法示例

标准验证点

检查对象属性值

检查某个单选按钮是否被选中

Standard-图像验证点Image

检查图像属性值

检查图片源文件名是否正确

Standard-表格验证点Table

检查表格中的信息

检查表格控件中某个单元格的值是否正确

Standard-页面验证点Page

检查网页的特性

检查网页加载所需的时间,以及网页上Link或图片Images的数量, broken links

文本、文本区域验证点

检查文本字符串是否显示在网页的适当位置。区别是文本区域检查点不支持web页面文字的检查,仅检查标准windows, vb, activex以及插件支持的控件的文本检查

检查预期的文本字符串是否显示在网页或对话框内

位图验证点

将网页或应用程序的某个区域捕获为位图并对其进行检查

检查网页或网页的某个部分是否按照预期显示

Accessibility checkpoint

网页可访问性检查,网页是否满足W3C网页内容可访问性指南的要求,section 508标准

’alt’属性设置检查,”FrameTitles”的检查等

数据库验证点

检查应用程序或网站所访问的数据库内容

检查数据库查询的记录集是否正确,数据记录是否被正确的添加到指定的表

HP QuickTest Professional User Guide > Appendixes > Supported Checkpoints and Output Values Per Add-In > Supported Checkpoints

²             Insert

n         Call to new action: reusable action则该action可以被调用

n         Call copy of action: 将其他脚本的action复制到本脚本

n         Call existing action: 调用外部reusable action

n         output value可以将值输出到data table,下次使用

n         Report向测试报告输出信息:

Reporter.ReportEnvent EnventStatus, ReportStepName,Details

EnventStatus: 0 or micPass, 1 or micFail, 2 or micDone, 3 or micWarning

Example: Reporter.ReportEnvent 0, “Step0”,”测试成功

n         Function Definition Generator: 创建自定义函数或sub,并且可以把该函数注册到标准控件的某一方法中. See help RegisterUserFunc statement

n         Step Generator: use utility objects, test objects, functions

Resources menu: object repository

²             Recovery Scenarios处理不可预见的事件,可预见的事件在代码中实现

n         Resources > Recovery scenario manager中添加事件定义和处理,并保存成一个文件.qrs

n         File > Settings>Recovery将上面的文件添加到scenarios

²             the Object RepositoryOR window for the local object repository, and the Object Repository Manager for shared object repositories.

²             关联Associate RepositoriesQTP为某个Action生成相应的测试文件和目录。OR也与Action绑定,因此新的Action不能直接使用前一个ActionOR,解决办法是录制新的OR或者使用关联。关联的OR不能修改,界面显示是灰的。

²             要编写高质量的脚本,除了参考VBScript coding conventions,还需要对对象库进行管理。可以修改对象名字,使他更易读;为了减少代码行长度,可以添加注释,适当分割对象,或者在对象库中调整层次关系,是底层控件上移。

Tools menu

²             Object identification:选择哪些属性来区别出一个唯一的控件

²             Object Spy可用于观察运行时对象的属性和方法。可以在界面上不断地改变测试对象,观察对象的属性和方法,通过这种方式了解控件行为,以及判断哪些属性可放到脚本中用于判断测试结果。

²             Tools > Web event recording configuration:

n         Basic: 标准对象上的click等最基本事件

n         Medium: Basic + HTML<Div><Span>等标签对象和事件

n         High: Medium + double click等高级事件

n         Custom settings

²             Data Driver将自动检测可能需要参数化的部分

²             虚拟对象Virtual object: 若程序中包括那些行为类似标准对象的对象,但不被QTP识别,则可将控件所在区域定义为虚拟对象,并可映射到某些标准对象button, check box, object, list, table, radio buttonQTP在测试过程中会对虚拟对象模拟执行用户操作。

²             View Options > Auto-expand VBScript syntax启动VBS语法识别,When a function library window or expert view is active

²             PathFinder.Locate(“xxxx.xxx”)查找某文件所在的目录全路径。在Tools > Options >Folders添加查找路径。

²             Tools > Options>Active screen设置录制过程中保存的对象级别,越高级后期编辑脚本越容易,但是录制过程更慢,需要更多的存储空间,默认是partial

1none

2minimum捕获和存储录制的对象及其父对象属性

3partial 捕获和存储第一个步骤所执行的应用程序窗口以及该窗口下属的对象属性

4complete捕获和存储所有信息,包括每个步骤中所有激活的窗口和对话框,web页面等

Keyword view, 参数化

²             Data table: 脚本目录下的default.xls, file>settings>Run对应global sheet属性,action call properties对应action sheet属性。

DataTable.AddSheet (SheetName)

DataTable.GetSheetCount

DataTable.DeleteSheet sheetId: sheetID可以是名字,也可以是IDID1开始

DataTable.GetCurrentRow 当前使用数据表中正在使用的行号

DataTable.GetRowCount 当前使用数据表的总行数

DataTable.Value(ParameterID[,SheetID]) sheetID当前行的ParmaterID列(列名或ID,从1开始)取值或赋值

²             Test/Action parameter:把action/testproperties中添加参数,转换成可重用的测试步骤

²             Random NumberRandomNumber(ParameterNameOrStartNumber[,EndNumber])

²             Environment对象(File > Settings > Environments):设置和读取环境变量。环境变量分built-in and user-defineduser-defined variable可以export/load。通常在以下情况使用环境变量:1)希望访问QTP的系统数据,如测试的名字,操作系统名字;2)希望存储数据,以备不同的action或函数使用。

Environment.value(“OS”)

Filename=Environment.ExternalFileName

If Filename=”” then

Environment.LoadFromFile(“xxx.xml”)

End if  

描述性编程

应对动态出现或变化的界面元素。用描述性编程写的脚本运行时,QTP使用脚本中的描述来查找对象,不是查对象库,而是与程序运行时QTP为其创建的临时测试对象版本进行匹配。

²             直接描述:如Dialog(“Login”).WinEdit(“attached text:=Agent Name:”).Set “mercury”

²             Description对象

Set MyDesc = Description.Create()

  MyDesc(“attached text”).value = “Agent Name:”

  Dialog(“Login”).WinEdit(MyDesc).Set “Mercury”

²             具有后续强迫性:一旦父对象开始使用描述性编程,则后续子对象都要使用描述性编程的方式出现

²             也可以用多个属性和值来标识控件,中间用“,”隔开。

²             描述控件属性的值被当成正则表达式处理,因此如果要包含“* ?”等字符,要在字符前加上“/”,或者设置MyDesc(“Regular Expression”).value = false

²             简化代码:如果描述的语句很长,可以将其赋予一个新变量,后续使用该新变量,或者用with语句。

²             childobjects对象中使用description对象,有选择性的获取子对象

MyDesc(“text”).value = “button.*”

Set MyChildObject = swfWindow(“Form1”).childobjects(MyDesc)

ChildCount=MyChildObject.count

For counter = 1 to ChildCount – 1

     MyChildObject(counter).click

Next

²             对控件动态属性的判断也可以使用GetROProperty,如

If xxxx.GetROProperty(“Enabled”) = true then xxx

QTP>Tools

²             QTP > Tools > Test Batch Runner批量运行测试脚本。必须选择Options > Run > Allow other HP products to run tests and components

²             QTP > Tools > Silent Test Runner可以在不打开QTP的时候运行测试,模拟LR的调用过程,统计事务执行时间。

²             LR中运行QTP脚本:

1)每台机器只能同时运行一个GUI Vuser

2)确保LR运行QTP脚本之前QTP已经关闭

3)确保启动一个QTP脚本之前,前一个QTP脚本已经关闭

常用语法,Utility object, Utility statements

GeneralHelp.chm > QuickTest Professional Object Model Reference

²             Utility Object > Utility statements

n         Print 非模式窗口。而MsgBox(prompt[,buttons][,title]) 模式窗口,会暂停执行直到关闭.

n         Wait 10 等待10秒,暂停执行

n         ExecuteFile “xxx.vbs” 执行指定的vbs脚本文件,且一旦被执行,脚本文件中的函数可以直接使用

²             Utility Object

n         Extern object加载DLL,可以用它来调用windows API函数

n         DotNetFactory对象访问.Net类库

Set var_createinstance = DotNetFactory.CreateInstance(“system.environment”)

Msgbox var_createinstance.CurrentDirectory

n         XMLUtil对象检查XML文档

Set doc=XMLUtil.CreateXML() ‘创建XMLData对象 (< supplemental objects)

Doc.LoadFile “Test.xml”

Ans=doc.validate(“d:/.../quickTest Prefessional/dat/objectRepository.xsd”) ‘validate指定某个schema文件,检查加载的xml是否满足schema格式要求

If ans then

     Msgbox “xml文件匹配指定的schema”

Else

     errNo=doc.GetValidationErrorsNumber

     for i=1 to errNo

            errStr=doc.GetValidationError(i)

            msgbox errStr

     next

end if

²             Standard windows

n         Standard Windows Standard Windows Standard WindowsSystemUtil object

used to control applications and processes during a run session

SystemUtil.Run file, [params], [dir], [op], [mode]打开程序或文件

SystemUtil.BlockInput, UnBlockInput屏蔽/取消屏蔽鼠标和键盘输入

CloseDescendentProcesses, CloseProcessByHwnd, CloseProcessById,

CloseProcessByName, CloseProcessByWndTitle 关闭进程

n         Standard Windows Standard Windows Standard WindowsSystemUtil.Run “logman”, “start perf_log”, SystemUtil.Run “logman”, “stop perf_log”

相当于打开perfmon工具,运行和停止perf_log性能日志

n         Desktop: CaptureBitmap CaptureBitmapCaptureBitmap截屏,ChildObjects, RunAnalog运行analog recording

n         常用方法和属性:exist判断控件是否存在,checkproperty(name, value)检查控件属性, GetROProperty(name)获取控件当前属性, WaitProperty(name,value,[timeout])等待控件的某一属性达到某值,直到超时

Object

Method,property

Static

Check

WinCalender

SetDate, SetTime

WinCheckBox

Set

WinComboBox

Select, GetItemsCount, GetItem(i) begin with 0

Window

Activate, Maximize,Restore, GetROProperty(“text”)

WinEdit

Set, SetSecure, GetROProperty(“text”)

WinEditor

Set, SetSecure, Type

WinList

Select

WinListView

Select, ExtendSelect

WinMenu

Select "File;Open... Ctrl+O", Select "<Item 1>;<Item 2>" Select "<Item 1>;<Item 2>", begin with 1

ItemPath =xxx.Menu("Menu").BuildMenuPath("View","Toolbars","Formatting")

Or ItemPath = xxx.BuildMenuPath(3,2,2)

Window("Some Window").WinMenu("Menu").Select ItemPath

WinRadioButton

Set

WinScrollbar

Set, NextLine, NextPage, PrevLine, PrevPage, GetROProperty(“maxscrollpos”)

WinSpin

Next, Prev, Set

WinStatusBar

GetContent, GetItemsCount, GetItem(i) begin with 0

WinTab

Select name or index(begin with 0), GetSelection

WinToolbar

Press name or index(begin with 1)

WinTreeView

Select, ExpandAll, Expand, Collapse

²             ActiveX控件,也叫OLE, OCX控件,可以插入到web页面或其他应用程序使用的组件或对象。同windows标准控件类似,有Exist, click, type, CheckProperty, GetROProperty

n         可以用object属性获取内部属性和方法,可以在debug viewexpert view窗口查看

n         AcxUtil.FireEnvent执行方法

Set SaveBtn = Browser("Homepage").Page("Welcome").AcxButton("Save").Object

AcxUtil.FireEvent SaveBtn, “Click”

²             VB object:用object获取内部属性和方法

²             Web对象

n         QTP只支持录制IE Browser,运行时则支持多种浏览器,如果机器上有安装多种,则可以在Automation > Record and run settings中设置用哪种浏览器

n         QTP不支持录制多Tab页的浏览行为,因此要关闭IE选项>高级>Enabled Tabbed Browsing

Page

Sync 等待页面加载完成, .object.links.length, .object.images.length

Image

.object.src图片来源,.object.width/height

Link

.CheckProperty(“url”,”http://....”), .object.href, click, FireEvent “click”

WebButton

Click

WebCheckBox

Set, object.value

WebEdit

Set, object.value

WebFile

Set “xxx.xxx”

WebList

Select, .object.value, GetROProperty(“selection”)

WebRadioGroup

Select, GetROProperty(“all items/items count/selected item index/value”)

WebTable

RowCount, ColumnCount, GetCellData(row,col), ChildItem(intRow,intCol,”link”,0).click

WebXML

Set obj=xxxx.GetData; obj.SaveFile “xxx.xml”, object.innertext

²             .Net插件用于识别和录制WPF(windows presentation foundation)控件,windows forms控件和web forms控件

n         NET WPF: object, AutomationElement返回和访问AutomationElemen暴露的标准属性,AutomationPattern返回Control Pattern的特定实例,SupportedPatterns判断某个控件是否支持某个模式

n         NET Windows Forms: 用工具.Net windows forms spy或者object获取内部属性和方法

n         NET Web Forms: object

²             Web service插件:可以让QTP分析指定的WSDL是否满足WS-I标准。需要使用第三方工具Interoperability testing tools (http://ws-i.org),在tools > options中加上工具目录,然后用tools > validate wsdl验证。

²             QTP Automation Object Model自动化对象模型,通过它自动控制QTP的各项操作,如启动和运行测试。

n         使用场景:1)初始化脚本,自动启动QTP,设置环境变量和选项;2)维护测试;3)从其他程序中调用QTP

n         QuickTest.Application

1)  Test:测试项目和脚本,File > Settings > Properties > Generate scripts

2)  Addins.Addin插件管理

3)  Options选项设置对话框, Tools > Options > General > Generate scripts

²             Build the Automation Framework

n         group tests

n         use function library

n         output the result

n         define the driver

²             Mercury.DeviceReplay对象用于模拟鼠标单击和移动,还有键盘输入等操作

http://blog.csdn.net/Testing_is_believing/archive/2008/06/02/2504745.aspx

 

Set DeviceReplay=createobject("Mercury.devicereplay")

DeviceReplay.SendString(“xxx”)

DeviceReplay.MouseMove 200,200

DeviceReplay.MouseClick 200,200,left_mouse_button

Const Vk_shift=42, vk_tab=15

DeviceReplay.KeyDown(vk_shift)

devicereplay.presskey VK_tab

VBScript语法:

工具VBSEdit, QTP help/VBScript56.CHM

l         VBScriptVB的安全子集,设计目的是在多平台上运行并能使用ActiveX接口,适合windows管理,网页脚本编程和开发测试脚本。

l         Option Explicit显示声明变量, 常量定义const, 变量只有一种数据类型Variant,可以包含各种不同的信息,这取决于信息如何被应用。可以用VarType获取变量子类型。

l         Dim A, AA(10)B(), ReDim B(10)ReDim Preserve B(20), 数组大小0~UBound(array)

l         变量作用域:过程级和script级(过程之外声明)

l         注释REM或者

l         Sub {subname}({arguments})

              {statements}

End Sub

Call subname(xxx,xxx) subname xxx,xxx

 

Function {function_name}({arguments})

              {statements}

           Function_name=xxx

End Function

        Exit Do

        Exit For

        Exit Function

        Exit Property

Exit Sub

l        On error resume next遇到错误或异常是继续执行下面的语句

l         参考VBScript56.CHM, vbscript

1User’s guide > VBScript Fundamentals > VBScript Features

operators&字符串连接),

strings函数: len, left, mid, right, InStr, InStrRev从结尾算起,LTrim, Rtrim, Trim, LCase, UCase, strComp, Split, Join

Conversions: Asc, Chr, CStr, CBool, CByte, CCur, CDate, CDbl, CInt, CLng, CSng

Variants判断函数:IsArray, IsDate, IsNull, IsObject, VarType, TypeName

MathIntFix, Int((upperbound - lowerbound + 1) * Rnd + lowerbound)

Randomize初始化随机数生成器

    Input/Output: InputBox, Msgbox

Control flow:

Do...Loop
For...Next
For Each...Next
If...Then...Else
Select Case
While...Wend
With

2User’s guide > VBScript Fundamentals > VBScript coding conventionsNaming conventions for objects, variables, and proceduresCommenting conventionsText formatting and indenting guidelines

3reference>constants>VarType constants

4reference>constants>String constants: vbCr=chr(13)回车carriage returnvbLf=chr(10)换行line feed, vbCrLf=chr(13) & chr(10)回车换行

5) reference>Miscellaneous>character set

6正则表达式user’s guide>introduction to regular expressions

reference > objects and collections > Regular Expression(RegExp) object:

51Testing软件测试网$W"Q8W:B,]5Z gZ 属性 Pattern(模式,要搜索的字符串格式), IgnoreCase(是否区分大小写), GlobalTrue全部匹配,False仅匹配第一个)

 方法 Test, Replace, Execute

Test用于对指定的字符串执行一个正则表达式搜索,并返回一个布尔值,表示是否找到匹配的模式。Replace替换找到的字符串。Execute执行搜索,返回Matches

l         VBScript56.CHM, script run-time > FileSystemObject object: 文件系统操作。

GetFolder指定文件夹,Files显示文件,GetFile指定文件,Attributes文件属性,CreateTextFile创建文件,Write/WriteLine/WriteBlackLine写文件,FileExists判断文件是否存在。CreateFolder创建文件夹,DeleteFolder删除文件夹,CopyFolder复制文件夹,MoveFolder移动文件夹

 

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值