《软件自动化测试成功之道》学习笔记

《软件自动化测试成功之道》读书笔记(1)

 

《软件自动化测试成功之道》学习路线

1、学习光盘附带的TestComplete和QTP的视频

2、学习TestComplete和QTP、《软件自动化测试成功之道》、《QTP自动化测试进阶》

3、使用TestComplete、QTP等自动化测试工具进行自动化测试实践

 

参考:

http://blog.csdn.net/Testing_is_believing/category/672903.aspx

 

 

TestComplete

AutomatedQA公司的自动化测试工具。 

主要特点:

支持VB Script、JScript、Delphi Script、C++ Script、C#Script作为脚本语言。一个工具就能支持功能自动化测试、WEB负载测试、分布式测试、单元测试等。

价格便宜:$999

目前最新版本:7.52

下载地址:

http://www.automatedqa.com/downloads/testcomplete/

 

 

选择自动化测试工具需要考虑的19个方面

在为自动化测试项目做工具选型时,需要考虑以下几个方面的因素来决定选择哪个自动化测试工具:

1、对不同类型的应用程序和平台的支持。

2、对不同类型的操作系统的支持。

3、对不同的测试类型的支持。

4、脚本语言、编辑器和调试器。

5、录制测试脚本的能力。

6、应对变化的能力。

7、对控件和对象的支持。

8、支持不同渠道的测试数据。

9、运行测试与测试对象的同步。

10、检查点。

11、测试结果记录和导出报告。

12、扩展性。

13、测试多语言应用程序的能力。

14、对团队协作和源代码管理的支持。

15、对命令行和OLE自动化的支持。

16、与团队协作系统以及软件构建系统的整合。

17、技术支持。

18、价格。

19、试用版。

 

《软件自动化测试成功之道》读书笔记(2)

学习《软件自动化测试成功之道》附带光盘中的TestComplete基础教程

1 TC简介.swf

2 安装.swf

3 White-Box Application.swf

4 项目创建(1).swf

5 项目创建(2).avi.swf

6 运行AUT.swf

7 Code Complete.swf

8 录制脚本.swf

 

参考:

TestComplete 6 中录制回放功能的使用介绍(视频):

http://tv.falafel.com/default/09-07-30/Record_And_Playback.aspx

 

TC8.0不仅修改了录制工具栏的设计,易用性更强了,可在录制时修改脚本名。而且在Opetions->Engines -> Recording中提供了“Record user actions over tested applications only”选项,可以让你仅仅录制选定的被测试程序。

 

另外,录制时会自动存储映射对象的方法和属性,这样录制完成后,即使关闭了被测试对象,也能访问对象的方法和属性。

 

 

学习《软件自动化测试成功之道》2自动化测试工具

 

Windows的API中封装了很多可用于自动化测试编程的函数,例如FindWindow、GetWindowRect等函数。这些函数可在编程语言或脚本代码中进行调用,从而实现自动化测试编程。

 

 

安装IE Developer ToolBar,学习DOM相关知识

(1)常用DOM 属性

        className.同一样式规则的元素用相同的类名。可通过className快速过滤出一组类似的元素。

        document.用于指向包含当前元素的文档对象。

        id.当前元素的标识。如果文档中包含多个相同id的元素,则返回一个数组。

        innerHTML.用于指向当前元素的开始标记和结束标记之间的所有文本和HTML标签。

        innerText.用于指向当前元素的开始标记和结束标记之间的所有文本和HTML标签。

        offsetHeight, offsetWidth.元素的高度和宽度。

        offsetLeft, offsetTop.当前元素相同对于父亲元素的左边位置和顶部位置。

        outerHTML.当前元素的开始标记和结束标记之间的所有文本和HTML标签。

        outerText.当前元素的开始标记和结束标记之间的所有文本,但不包括HTML标签。

        parentElement.当前元素的父亲元素。

        sourceIndex.元素在document.all集合中的索引(index)。

        style.元素的样式表单属性。

        tagName.当前元素的标签名。

        title.在IE中,代表元素的tool tip文本。

(2)常用DOM方法

        click().模拟用户对当前元素的鼠标点击。

        contains(element).用于判断当前元素是否包含指定的元素。

        getAttribute(attributeName, caseSensitive).返回当前元素所包含的某个属性,参数attributeName为属性名、caseSensitive表示是否大小写敏感。

        setAttribute(attributeName, value, caseSenstive). 设置当前元素的属性。

(3)常用DOM 集合

        All[].当前元素中包含的所有HTML元素的数组。

        children[].当前元素包含的孩子元素。

 

 

使用HTML DOM进行自动化测试的简单例子

 

把下面VBScript脚本另存为GoogleTest.vbs,双击运行:

 

Dim oIee, objedit

Dim oPagtxt

 

Set oIee = CreateObject("InternetExplorer.Application")

 

oIee.navigate ("http://www.google.com.hk")

oIee.Visible = True

 

Do While oIee.readystate <> 4

Loop

 

Set oPagtxt = oIee.document

set objedit = oPagtxt.getelementsbyname("q")

objedit(0).value = "QTP自动化测试进阶"

 

set objbutton = oPagtxt.getelementsbyname("btnG")

objbutton(0).Click

 

Set oIee = Nothing

 

 

 

对于TC而言,C、C++、Delphi等程序,被称为Black Box应用程序,而像.NET、JAVA等基于中间代码构建的应用程序,被称为White Box应用程序。

 

参考:

http://www.docin.com/p-41427745.html

 

《软件自动化测试成功之道》读书笔记(3)

学习《软件自动化测试成功之道》附带光盘中的TestComplete基础教程

9 Object Browser(1).swf

10 Object Browser(2).avi.swf

11 Object Browser(3).avi.swf

 

 

TC的对象浏览器提供了强大的查看界面对象属性、方法的功能。在自动化测试脚本编写过程中需要经常使用的工具!

 

 

参考:

官方主页上关于TC Object Browser的介绍:

http://www.automatedqa.com/products/testcomplete/object-browser/

 

TestComplete 6 中对象浏览器(Object Browser)的使用介绍(视频): 

Using The Object Browser

http://tv.falafel.com/default/09-07-30/Using_The_Object_Browser.aspx

 

 

转载:

TestComplete 对象浏览器(Object Browser)和进程相互影响以及解决办法

前两天,刚刚学习使用TestComplete(以下简称TC)录制脚本,在录制过程中,发现TC的对象浏览器(Object Browser,以下简称OB)和被测程序本身或者其调用和产生的进程存在着相互的影响。因为OB本身的功能就是显示当前系统的所有进程,而当被测程序在运行过程中生成了某个实例(比如Word,Excel等等),那么由于OB的存在,此时被测程序是无法通过释放实例来将其进程销毁的!此时OB的现象是无法刷新!因此,只能使用强制结束进程的方法将进程过掉后,脚本才能正常回放成功!

 

《软件自动化测试成功之道》读书笔记(4)

学习《软件自动化测试成功之道》附带光盘中的TestComplete基础教程

12 Test Log(1).swf

13 Test Log(2).swf

14 Test Log(3).swf

 

测试日志记录是自动化测试不可获取的一部分,详细的日志记录有助于脚本的调试和软件的问题分析。

 

TestComplete附带的Sample中有专门一个例子Test Log讲解如何写入各种测试日志

Illustrates posting a variety of pictures and messages to the test log and organizing them as a hierarchy of folders in the test log.

<TestComplete Samples>\Scripts\Test Log

 

TC 的 Log 可以写 6 种类型的信息:

· Message - Can come from TestComplete or from the script code (Log.Message), will not cause the test to fail.

· Warning - Can come from TestComplete or from the script code (Log.Warning), not necessary a failure for the test but could be an indicator for why a test failed.

· Error - Can come from TestComplete or from the script code (Log.Error), this indicates a failure for the test.

· Events - Usually comes from TestComplete but can come from the script as well (Log.Event), does not cause the test to fail. TestComplete generates an event for every mouse-click or keyboard entry in the test.

· Image - Usually comes from script code (Log.Picture) but TestComplete can generate as well (Region Checkpoints).

· File - There are two types of File log items. Log.File, will copy the file into the directory holding the log XML file and creates a hyperlink to the file. Log.Link just creates a hyperlink to the file without copying the file.

 

 

《软件自动化测试成功之道》读书笔记(5)

学习《软件自动化测试成功之道》附带光盘中的TestComplete基础教程

15 调试脚本.swf

 

 

调试是脚本开发的基本功!

 

step into表示调试时碰到函数将进入函数体内

step over表示调试时一步一行跳过

run to cursor表示运行到光标所在行后停住

 

用VBScript的MsgBox显示信息,或者把变量、对象属性、数据等写入Log也是一种很好的调试方法!

 

 

参考视频:

在TC中调试脚本:

http://www.automatedqa.com/products/testcomplete/screencasts/debugging/

Debugging Automated Test Scripts With TestComplete

Describes the automated test script debugging features provided by TestComplete.

 

TestComplete代码基本调试技巧:

TestComplete Basic Debugging

http://tv.falafel.com/default/09-08-01/TestComplete_Basic_Debugging.aspx

 

 

《软件自动化测试成功之道》读书笔记(6)

 

学习《软件自动化测试成功之道》附带光盘中的TestComplete基础教程

16 比较文件(1).swf

17 比较文件(2).swf

18 比较对象属性.swf

 

检查点是自动化测试必不可少的部分,就像测试用例如果缺少了最后的测试结果检查就不是完整的测试用例一样,自动化测试脚本中也需要添加检查步骤。一般通过检查控件对象的属性、文件、数据库数据等来判断测试是否通过。

 

TestComplete支持Region、File、Object等类型的检查点。

 

Region CheckPoint的例子: 

       Sub RegionCompareExample 

              If (Not Regions.Compare("Logo", Sys.Process("iexplore"). _

                     Page("http://www.activefocus.net/").Table(0).Cell(1, 0). _

                     Link(0).Image("nav_r1_c1"), False, False, True, 0)) Then

              Call Log.Error("The regions are not identical.") 

              End If

       End Sub

File CheckPoint的例子: 

       Sub FileCompareExample 

              If (Not Files.Compare("Sample1.txt", "Sample2.txt", 0, True)) Then 

              Call Log.Error("The files are not identical.") 

              End If

       End Sub

Object CheckPoint的例子:

       Sub ObjectCompareExample

              If (Not Objects.Compare(Sys.Process("iexplore").Page("http://www.activefocus.net/").Panel(0), "Panel", True)) Then

              Call Log.Error("The objects are not identical.")

              End If

       End Sub

 

 

参考TestComplete附带的Sample例子进行练习:

Checkpoints Samples(检查点的使用)

TestComplete includes a number of samples that demonstrate how to perform various kinds of checkpoints:

Database Table Checkpoints(数据表检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\DatabaseTableCheckpoints\

File Checkpoints(文件检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\FileCheckpoints\

Object Checkpoints(对象检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\ObjectCheckpoints\

Property Checkpoints(属性检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\PropertyCheckpoints\

Region Checkpoints(区域检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\RegionCheckpoints\

Table Checkpoints(表格检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\TableCheckpoints\

WebAccessibility CheckpointsWeb可访问性检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\WebAccessibilityCheckpoints\

WebComparison CheckpointsWeb对比检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\WebComparisonCheckpoints\

Web Service CheckpointsWeb Service检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\WebServiceCheckpoints\

XML CheckpointsXML检查点):

<TestComplete Samples>\Scripts\CheckpointsSamples\XMLCheckpoints\

 

 

TestComplete 6 中对象检查点的使用介绍(视频):

Object Checkpoints

http://tv.falafel.com/default/09-07-30/Object_Checkpoints.aspx

 

 

在TestComplete的关键字视图中如何使用Stores和Checkpoints进行对象属性、表格数据、文件的检查?(视频):

Using Stores & Checkpoints in a TestComplete Keyword Test

In this video we look using Stores & Checkpoints, a powerful feature of TestComplete, providing the ability to capture test data during test recording. We examine TestComplete v7’s new Checkpoint Wizard feature and incorporate the following Checkpoints within the test:

* Object (multiple object/property comparison)
* Table, verifying tabular data
* File, comparing data created during the test

http://tv.falafel.com/default/09-09-07/Using_Stores_amp_Checkpoints_in_a_TestComplete_Keyword_Test.aspx

 

 

如何在TestComplete中整合Beyond Compare进行文件比较?(视频):

TestComplete file compare with Beyond Compare

http://tv.falafel.com/default/09-08-16/TestComplete_file_compare_with_Beyond_Compare.aspx

 

 

 

《软件自动化测试成功之道》读书笔记(7)

学习《软件自动化测试成功之道》附带光盘中的TestComplete基础教程

19 数据驱动(1).swf

20 数据驱动(2).swf

 

 

TC用DDT来支持数据驱动测试,DDT包括3种类型:

(1) CVSDriver is used to read text file such as comma delimited (default) or tab delimited (using a schema.ini file). By default the first row is the header information (or column names) for the driver.

(2) ExcelDriver is used to read an Excel spreadsheet. The first row of the sheet is the header information for the driver.

(3) ADODriver is a generic driver to read in ADO compatible data source.

 

 

阅读《软件自动化测试成功之道》的第6章 “自动化测试框架的搭建”

 

数据驱动框架与关键字驱动框架类似,测试数据都存储在数据库或Excel文件,但是数据驱动框架的测试用例、测试步骤和测试逻辑是在测试脚本中编写的,而不像关键字驱动框架一样放在表格中。

 

脚本从表格中读入测试数据,包括测试输入的数据,测试结果验证的数据。通过循环遍历数据表格中的所有行,可以极大地增大测试覆盖面,测试各种输入条件下应用程序的表现。

 

 

学习TestComplete附带的Sample:

DDT(数据驱动测试)

This sample is used by the Data-Driven Testing Tutorial that describes a step-by-step procedure of creating data-driven tests in TestComplete. The script tests the OrdersDemo application, which is used to configure a table of purchase orders. The script reads data from an Excel sheet and adds new records to the table.

Excel file and TestComplete project suite:

<TestComplete Samples>\Scripts\DDT

DDT&NameMapping(数据驱动测试,使用NameMapping

Illustrates how to perform data-driven tests in TestComplete. See also Data-Driven Testing. The script tests the OrdersDemo application, which is used to configure a table of purchase orders. The script adds new records to the table and modifies existing ones. The data the script enters to table records are taken from different sources: a multidimensional array defined directly in the script, a comma-separated values (CSV) file that the script accesses via Scripting.FileSystemObject, a CSV file that the script accesses via ADO, a Microsoft Access database that the script accesses via ADO and an Excel file that the script accesses via ADO. In order to unify the testing of the language-specific implementations of the OrdersDemo application (there are versions written in Microsoft Visual C++, Microsoft Visual Basic, Borland Delphi and Borland C++Builder), the script uses custom object names. See Name Mapping.

Data:

<TestComplete Samples>\Scripts\DDT&NameMapping\Data

TestComplete project suite:

<TestComplete Samples>\Scripts\DDT&NameMapping

 

 

TestComplete数据驱动测试的视频:

http://www.automatedqa.com/videos/data-driven-testing-testcomplete-webinar/

如何在TestComplete的关键字视图中使用DDT实现数据驱动?(视频):

Data Driven Testing in Keyword Testing 

http://tv.falafel.com/default/09-08-15/Data_Driven_Testing_in_Keyword_Testing.aspx

如何在TestComplete中使用CSV文件进行数据驱动测试?(视频):

Data Driven Testing With CSV files

http://tv.falafel.com/default/09-07-30/Data_Driven_Testing_With_CSV_files.aspx

如何在TestComplete中使用数据库表进行数据驱动测试?(视频):

Data Driven Testing With database Tables

http://tv.falafel.com/default/09-07-30/Data_Driven_Testing_With_database_Tables.aspx

 

 

《软件自动化测试成功之道》读书笔记(8)

学习《软件自动化测试成功之道》附带光盘中的TestComplete基础教程

21 事件处理(1).swf

22 事件处理(2).swf

 

 

TC的事件处理机制类似于QTP的场景恢复机制,一般用于处理非预期异常事件、非预期弹出窗口。

 

TC中可处理的一般事件包括:

       OnLogCloseNode         Occurs when a log folder is pop off the log.

       OnLogCreateNode        Occurs when a new log folder is appended on the log.

       OnLogError          Occurs when an error message is posted to the log.

       OnLogEvent          Occurs when an event message is posted to the log.

       OnLogFile             Occurs when a file is posted to the log.

       OnLogLink           Occurs when a file reference (link) is posted to the log.

       OnLogMessage            Occurs when a information message is posted to the log.

       OnLogPicture               Occurs when a picture (image) is posted to the log.

       OnLogWarning             Occurs when a warning message is posted to the log.

       OnOverlappingWindow  Occurs when a overlapping window appears.

       OnTimeout           Occurs when a timeout expires in a project or project suite.

       OnUnexpectedWindow   Occurs when an unexpected window appears.

       OnValidate             Occurs when the objects Validate method is called.

 

 

下面的脚本用于处理OnLogError事件,当Log一个错误时,把当前的桌面截屏并写入日志:

       Sub GeneralEvents_OnLogError(Sender, LogParams)

       Call Log.Picture(Sys.Desktop,LogParams.Str)

       End Sub

 

 

学习《软件自动化测试成功之道》第12章“非预期窗口的处理”。

 

在自动化测试项目过程中,我们必然会遇到一些非预期窗口,这些窗口或界面不在我们所编写的脚本中处理,例如一些异常窗口。不同的测试工具对于非预期窗口有不同的处理机制,例如QTP中采用Recovery Senario机制,而TestComplete则可以采用两种方式。

 

在TestComplete中,可以通过默认项目的属性设置来决定非预期窗口的默认处理方法,方法是选择菜单“Tools | Default Project Properties”,然后在如图12.1所示的界面中选择Playback,在“On unexpected Window”中选择非预期窗口的默认处理方法。

 

也可以编写事件代理脚本进行自定义处理。

 

研读TestComplete附带Sample中的Events脚本例子:

Illustrates how to handle events with TestComplete scripts. The main script posts messages of different types to the test log, launches Windows Notepad, opens the About box and then closes it. Event handlers that are defined in the script perform additional actions once the corresponding events occur. For instance, the handler of the OnLogError event changes the priority of the posted message, while the handler of the OnUnexpectedWindow event saves the screenshot of Notepad’s About box, which TestComplete treats as an unexpected window.

<TestComplete Samples>\Scripts\Events

 

参考:

Handling Unexpected Windows in Automated Tests

http://www.automatedqa.com/techpapers/testcomplete/handling-unexpected-windows/

 

 

 

 

 

posted on 2010-06-26 21:48  TIB  阅读(5429)  评论(0编辑  收藏  举报

导航