1、1录制技术的不足目前一些录制技术被应用到图形用户界面的自动化测试中,在软件开发周期中,系统需要不断地更新和维护,为了保证测试质量,测试代码对不断变化的系统要有很强的适应能力,换句话说,测试也同样需要维护。测试脚本的录制过程是根据具体的界面和操作进行的,一旦脚本的执行界面发生改变,运行就会出现异常,甚至仅仅是被操作对象位置的改变或图像分辨率的改变都可能会造成图形用户界面自动化测试的失败,因此,基于录制技术的自动化测试维护的代价相当高。另外,脚本录制的过程是固定的,所以脚本的运行会完全按照操作步骤,不具备灵活性。2自动化测试框架的提出在目前的软件测试中,一个备受关注的问题是如何高效地实现图形用户界
2、面的自动化测试,并使测试代码具有很高的灵活性。本文提出了一种基于对象捕捉技术的图形用户界面自动化测试框架GUIATF(Graphics User Interface Automation Testing Framework),为测试人员方便地创建并灵活地维护测试代码提供保证。当用户界面发生变化时,测试代码能很快地进行更新,对用户界面的变化有很强的适应能力。3GUIATF框架的工作原理GUIATF框架的基础是消息机制,通过消息的发送来触发相应的事件。消息的初始接收器必须是窗口对象。Windows消息通常直接由该窗口对象处理。通常产生于应用程序主框架窗口的命令消息被传送到命令传送中描述的命令目标链
3、。GUIATF框架要完成的任务是为测试人员开发自动化测试代码提供功能强大的接口,模拟测试用例中定义的用户操作,通知系统发送一系列的消息给应用程序,实现测试用例的自动化运行。3.1 GUIATF的作用图1GUIATF的作用从图1可以看出GUIATF将消息发送给系统,系统响应消息之后通知应用程序来触发对应的事件,完成测试用例中定义的一系列用户操作。GUIATF是连接应用程序和用户操作的桥梁。在自动化测试过程中,测试用例是批量运行的,为了跟踪测试结果,GUIATF需要不断记录执行过程、探测不期望出现的事件以及在运行异常时保存现场截图。这些结果数据通过日志管理存储在日志数据库中,便于测试人员查看和分析
4、测试结果。3.2 GUIATF的结构GUIATF框架由四个模块构成:对象定位、字符转换、消息发送和日志记录,如图2所示。对象定位模块将用户要操作的控件对象转化为GUIATF框架自身定义的自动化对象,然后再对其定位,在定位过程中,需要获取控件的一些属性信息,最常用到的是控件显示在界面上的名称。在不同的语言版本中,同一个控件的名称是不同的,字符转换模块提取当前环境的语言类型,将要检索的控件名称转换为当前语言环境中对应的名称,发送给对象定位模块。对象定位成功后,消息发送模块将模拟用户操作的消息发送到被锁定的对象,比如:用鼠标点击被定位的按钮或在被定位的编辑框中录入信息等。在以上三个模块执行的过程中,
5、日志跟踪模块分别记录它们工作的详细信息,以便自动化测试运行结束后,测试人员通过查看日志信息分析测试结果。图2GUIATF的结构(1)对象定位模块对象定位模块使GUIATF框架在处理控件对象方面具备功能丰富的接口,测试人员通过调用它们可以方便、高效地实现自动化对象的创建、检索自动化对象包含的子对象、激活对象、确定对象角色、状态和位置等功能。应用程序中的每一个控件都属于主窗口中的子窗口,包括按钮、编辑框等,它们都是Windows系统中的窗口。每个窗口都有一个窗口句柄作为其在系统中的唯一标识,对象定位模块通过获取窗口句柄将其转化为自身定义的自动化对象,主要定义如表1所示。表1 对象定位模块主要成员函
6、数及属性成员函数及属性功能Public Constructor(stringName)根据空间名称创建自动化对象internal bool CheckForUnexpected Window()检测不期望弹出的窗口Public AllSearch FindAllChildren( string FindName)检索所有子对象PublicWinObj FindChild(Roles FindRole)检索某个制定的子对象Public bool VerifyChildDoesNotExist(Roles FindRole)验证子对象不存在Public int ChildCountget;自对象数
7、量(属性)Public intWindowHandleget;对象窗口句柄(属性)Public string Stateget;对象状态(属性)Public Roles Roleget;对象角色(属性)Public Rectangle Positionget;set;对象位置(属性)(2)字符转换模块字符转换模块实现了GUIATF框架跨语言自动化测试的能力。它将自动化对象的属性信息动态转换为当前语言环境下对应的表现形式。在应用程序中存在的每一个字符串都有一个ID值,唯一地标识该字符串的含义,我们把它称为键(KEY),对于一个键,可以对应多个值(VALUE),每一个值代表一种语言的表现形式。应用
8、程序中包含的所有字符串组成一个键的集合,这个键集合对应了多个值集合,每一个值集合相当于一个语言包。比如:我们将一个英文版的应用程序汉化的过程就是用中文语言包中的汉语将英文替换。图3 字符转换过程使用GUIATF 框架提供的接口查找控件对象时,要实现跨语言就不能使用控件对象在一种具体语言下的名称,而要通过此名称的ID 号,也就是键(KEY),根据所获取当前语言环境的类型,动态转换对应的字符表现形式。转换过程如图3所示:在得到要转换字符串的ID值之后,首先确认数据库的配置参数,包括存放数据库的服务器名称,数据库名称,当前语言类型和格式等,然后创建与数据库的连接,把要查找的语言类型和字符串作为参数传
9、递给查询命令,执行查询就可以获取我们需要的转换结果。(3)消息发送模块自动化对象定位之后,消息发送模块提供相应的接口将消息发送给系统,系统响应后通知应用程序触发自动化对象执行对应的事件。在这个模块中,主要封装了鼠标消息类型、键盘消息类型以及消息发送的控制逻辑。鼠标消息类型根据用户使用它的行为定义,包括左键单击、左键双击、右键单击和拖动。Define moduleMouseMessagepublic boolDragAndDrop (WinObj From, WinObj To) ;publicWinObj GetPopupMenu ( ) ;public void LeftClick ( )
10、;public void LeftDoubleClick ( ) ;public voidMove ( Point Pos) ;public void RightClick ( ) ;键盘消息类型定义了单键的按下、弹起,多键的选择,字符串的录入以及功能键对自动化对象的控制。Define module KeyBoardMessagepublic void KeyDown (Keys Key) ;public void KeyUp (Keys Key) ;public void Type (Keys KeyArray) ;public void Type ( string Text) ;publi
11、c bool Type (WinObjWObject, Keys Key) ;public bool Type (WinObjWObject, Keys KeyArray) ;图形用户界面的操作效率受机器性能的影响,当需要点击某个对话框的一个按钮时,向系统发出打开对话框的消息要等待响应,在不同的机器或环境中,响应的时间是不一样的,如果对话框没有出现就触发点击按钮的消息会导致操作的失败,因此,消息的发送需要一定的控制逻辑来协调,包括:根据用户界面状态的变化判断用户进程何时失效,确保相关消息响应之后触发对应操作的执行。主要定义如下所示:Define module ControlLogicpubli
12、c boolWaitProcessIdle (WinObjWObject) ;public bool StateChange (WinObjWObject, StatesState, ) ;publicWinObjWaitDialogBox( string NameStartsWith) ;publicWinObjWaitWindow ( string NameStartsWith) ;publicWinObjWaitMessageBox( string NameStartsWith) ;(4)日志记录模块在测试用例的批量自动化运行过程中,日志记录不仅需要包含测试用例的执行细节,而且还要提供测
13、试用例执行的环境、时间、次数和状态等信息,这些信息都是测试用例管理器负责的。GUIATF框架的日志记录模块通过调用测试用例管理器提供的接口实现日志的存储和查询。4GUIATF框架的优势(1)方便测试用例的创建和修改:GUIATF框架的设计思想是基于对象捕捉的,只要被操作对象存在于用户界面中,即使位置或图像分辨率发生变化,测试代码会根据对象的特征进行准确地定位并对其操作。(2)详细的运行日志:提供详细、准确的运行日志并检测不期望弹出的对话框,保存错误现场的截图,使测试人员快速地定位存在的错误。(3)语言中立:提供测试代码的多语言支持,一份测试代码可以成功地运行在多语言环境中,完美地实现了自动化测
14、试的跨语言能力。5结束语GUIATF框架提供了功能丰富的接口,大大提高了用户界面自动化测试代码的开发效率。测试人员通过调用GUIATF框架提供的功能可以高效、灵活地实现测试逻辑,不会像录制技术那样因为测试脚本的固定使得测试很难维护。在模拟多用户的并发操作中,GUIATF框架在实现多机并发操作中还存在一定的不足,目前虽然实现了多机进程间的通讯和同步,但是和测试用例管理器还没有建立连接,没有实现并发测试批量运行日志的统一管理。另外,多机运行并发测试在调试方面也比较复杂,对调试技巧有很高的要求,在下阶段的工作中将对其进行重点研究。附录2外文原文Research on GUI Automation T
15、esting25Abstract: This paper points out the obvious deficiencies of recording technique in testing automation at present, aiming at constantly variational GUI , adopts objectoriented cap turing technique , designs GU IATF framework based on Windows message mechanism and imp lements GUI automation te
16、sting , largely imp roved agility of automation testing.Key words: software testing; regression testing; automation0.IntroductionIs a test designed to assess a program or system attributes or the ability to determine whether it meets the required results of its activities.In the entire software deve
17、lopment process, from needs analysis to the system design until the realization of the code, there will be more or less the issue.How to protect the quality of software, software testing has become the key technology. Software testing the heavy workload and has a repetitive, especially in the latter
18、 part of tests conducted by the regression testing (regression testing in the development of software changes and amendments to change when running), the need to verify before the problems identified in the new version In the solution, most of the tests are repeated.Implementation of the automated s
19、oftware testing can make a lot of testing procedures and implementation of repeated, not only saving a lot of labor, but also improve the efficiency of testing and quality assurance testing.1.The lack of recording technologyAt present, some recording technology has been applied to the graphical user
20、 interface of the automated test, in the software development cycle, the system needs to constantly update and maintain, in order to guarantee the quality of testing, testing code to changing the system have a strong sense of adaptability to change Saying that the test is also the need to preserve.T
21、est script recording process is based on the specific operation of the interface and, once the script of the implementation of the interface change, there will be abnormal operation, or even just be operating targets or change the location of the image resolution of the changes may result in graphic
22、al user The failure of automated testing interface, therefore , based on the recording of the cost of maintaining automated test is quite high. In addition, the script of the recording process is fixed, so the script will run in full accordance with the steps, and do not have flexibility.2.Automated
23、 test framework of the proposedIn the current software testing, one area of concern is how to achieve efficient graphical user interface of the automated test , and test code with high flexibility . This paper presents a target capture technology - based graphical user interface automated test frame
24、work GUIATF ( Graphics User Interface Automation Testing Framework ) , for the test easily create and maintain flexibility in the testing code to provide guarantee . When the user interface changes , test code can be quickly updated , the changes in the user interface has a strong adaptability.3.GUI
25、ATF framework of the working principleGUIATF framework is based on the information mechanism, the message sent through the appropriate incident to trigger . The initial news receiver must be the window object . Windows message usually directly targeted by the window treatment . Application procedure
26、s are usually produced in the framework of the main window to order message sent to transmit an order described in the order linked objectives . GUIATF framework to complete the task is to test the development of automated test code provides a powerful interface , simulation test case in the definit
27、ion of user actions , the notification system sent the message to a series of applications , and automated test case run.3.1The role of GUIATFFigure 1 GUIATF roleCan be seen from Figure 1 GUIATF will send a message to the system , the system response to the news notification application to trigger t
28、he corresponding events , completed a series of test cases in the definition of user actions. GUIATF is connected applications and user operation of the bridge . In the automated testing process , the test case is the bulk of the running , in order to track tes results , GUIATF need to keep records
29、of the implementation process, detection do not expect the incident and the preservation of the scene when the abnormal operation of a screenshot . The results of data storage management through the logs in the log database to facilitate analysis of test personnel to view and test results.3.2 GUIATF
30、 the structure GUIATF a framework of four modules: object positioning, character transformation, messaging and logging, as shown in Figure 2. Object module will be targeted users to control the operation of objects into the framework of their own definition of GUIATF automation object, and then its position in the positioning process, the need to acquire control of a number of attributes, most often used is displayed in control Interface name. In a different language versions of the same controls are different from the name, character conversion module from the current environment of the type
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1