QTP知识总结(一)

QTP知识总结(一)

(2010-12-22 16:30:41)
标签:

杂谈

分类: QTP

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         统计某操作所需的时间

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

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>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 PrefessionaldatobjectRepository.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         SystemUtil 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         SystemUtil.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])等待控件的某一属性达到某值,直到超时

Web对象

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

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

原文地址:https://www.cnblogs.com/edwardsun/p/3441776.html