Winrunner 教程_基础篇


Winrunner 工具介绍 (基础篇) 顾文炯 @ SJCU. 04/21/2010 ONLY FOR SJCU Presentation 目录  Winrunner 简介  Winrunner 实例演示  Winrunner 测试流程和演示  Winrunner 检查点和演示 Q & A ONLY FOR SJCU Presentation Winrunner 简介 • 根据典型软件生命周期模型,按阶段来分,软件测试分为以下阶段 – 单元测试 – 集成测试 – 确认测试 – 系统测试 – 回归测试 以上测试工作若全部由手工测试完成,那不但工作效率低下,而且很容易引入人工的 错误。因此,在当今的测试技术领域,一般引进自动化测试的方法。 • 自动化测试是指利用软件工具来控制测试的执行,进行预测与实际结 果的比较,并且自动生成测试报告等一系列的功能 : ONLY FOR SJCU Presentation Winrunner 简介 • HP (Mercury) WinRunner为我们提供有力的工具进行企业级自动化 的功能测试和回归测试。它自动捕获、验证并重放用户交互,以便 确定故障并确保部署中的业务流程能顺利实施并保持稳定。 • 一般运用于功能测试和回归测试。 • 优点 – 1、通过自动代替手工测试,缩短测试时间 、避免人为错误。 – 2、通过在升级应用程序时修改和重用测试脚本,尽量提高投资回报(ROI) • 不足 – 1.脚本维护需要成本 – 2.自动化一般达不到100% ONLY FOR SJCU Presentation Winrunner 简介-界面 ONLY FOR SJCU Presentation Winrunner 实例演示—订一张飞机票 飞机票订票系统演示 1)Login: name/password: Agent/Mercury 2) New order: 3) Open order: 4) Cancel order: 5) Search order: 6) Analysis: 7) Help: 8) About: 9) C:\Program Files\Mercury Interactive\WinRunner\samples\flight\tests\instords Refer C:\Program Files\Mercury Interactive\WinRunner\samples\flight\tests\instords APP: C:\Program Files\Mercury Interactive\WinRunner\samples\flight\app\flight1a.exe ONLY FOR SJCU Presentation Winrunner 测试流程 • 官方推荐 ONLY FOR SJCU Presentation 流程 1. Create GUI Map • GUI applications are made up of GUI objects such as windows, buttons, lists, and menus. • GUI Map指图形用户接口地图,Winrunner正是通过这张地图来找到 软件中的每一个按键、输入框等等。 • WinRunner stores the information it learns in a GUI map. When WinRunner runs a test, it uses the GUI map to locate objects: It reads an object’s description in the GUI map and then looks for an object with the same properties in the application being tested. • Refer to Lesson 3 ONLY FOR SJCU Presentation 流程 1. Create GUI Map –理解WR 如何识别GUI组件 • 每个GUI组件都有一组属性,在context sensitive模式下, WinRunner learns these properties and uses them to identify and locate GUI objects during a test run. Note that in Context Sensitive mode, WinRunner does not need to know the physical location of a GUI object to identify it. • When WinRunner learns the description of a GUI object, it looks at the object’s physical properties. Each GUI object has many physical properties such as class, label, width, height, handle, and enabled to name a few. WinRunner only learns the properties it needs to uniquely distinguish an object from all other objects in the application. – For example, when WinRunner looks at an OK button, it might recognize that the button is located in an Open window, belongs to the push_button object class, and has the text label OK. ONLY FOR SJCU Presentation 流程 1. Create GUI Map –理解WR 如何识别GUI组件 ONLY FOR SJCU Presentation 流程 1. Create GUI Map – GUI Map Mode • The GUI Map File per Test Mode – In the GUI Map File per Test mode, a GUI map file is created automatically every time you create a new test. The GUI map file that corresponds to your test is automatically saved whenever you save your test and automatically loaded whenever you open your test. – If you are new to WinRunner or to testing, you may want to consider working in the GUI Map File per Test mode. This is the simplest mode for inexperienced testers and for ensuring that updated GUI map files are saved and loaded. • The Global GUI Map File Mode – In the Global GUI Map File mode, you can use a single GUI map for a group of tests. When you work in the Global GUI Map File mode, you need to save the information that WinRunner learns about the properties into a GUI map file. When you run a test, you must load the appropriate GUI map file. – If you are familiar with WinRunner or with testing, it is probably most efficient to work in the Global GUI Map File mode. • Setting Your Preferred GUI Map File Mode – By default, WinRunner is set to the Global GUI Map File mode. To change the mode to the GUI Map File per Test mode choose Tools > General Options, select the General category, and select GUI Map File per Test. Click OK to close the dialog box. ONLY FOR SJCU Presentation 流程 1. Create GUI Map 演示–制作一个GUI Map Refer to Lesson 3 ONLY FOR SJCU Presentation 流程 2. Create Tests • Winrunner有两种录制模式:Context Sensitive和Analog。 – Context Sensitive模式录制我们对每个组件的操作行为,但是并不录制你的鼠标轨 迹。 – Analog模式也录制你的鼠标轨迹。因此,当我们测试绘图板之类的与路径相关的软 件时,才会用到这种模式。 • Winrunner录制我们操作软件的过程,并把它自动转化为测试脚本语言 (TSL)。 • 当我们录制好一段脚本后,我们可以修改自动生成的脚本,用运TSL使我们的 脚本更加聪明,例如识别错误、查看某短文字是否出现在界面中等等 Refer to Lesson 3 ONLY FOR SJCU Presentation 流程 2. Create Tests演示–录制、修改一个脚本 Refer to Lesson 3 ONLY FOR SJCU Presentation 流程 3. Debug Tests • 脚本也是程序,需要纠错,来保证测试任务顺利完成。通过设置程序断点,监 控变量来排查脚本中的语法错误和逻辑错误。 ONLY FOR SJCU Presentation 流程 3. Debug Tests演示–Debug 一个脚本 F6 step by step Right-click specific line Refer to Lesson 3 ONLY FOR SJCU Presentation 流程 4. Run Tests • 我们用Verify模式来运行我们的脚本,运行过程中程序记录各种错误和异常并 记录在测试结果。我们可以一次批量运行多个测试脚本。普通模式下,当测试 任务执行错误时,系统会提示是否继续运行。 • 在批量模式下,任何错误都不会打断测试任务继续进行。因此,我们可以在无 人看守的情况下运行脚本,例如在深夜运行它们。 ONLY FOR SJCU Presentation 流程 4. Run Tests 演示–执行单个、多个脚本 Refer to Lesson batch ONLY FOR SJCU Presentation 流程 5. View Results • 当测试任务结束后,系统会自动生成测试结果报告,测试结果报告显示了每个 测试脚本运行情况,并记录了运行期间的发生的主要事情,例如检查点检测情 况、错误信息等。 • 当测试点测试出不匹配现象,测试结果报告中会显示出预期结果和实际结果。 ONLY FOR SJCU Presentation 流程 6. Report Defects • 可以编写脚本语言,当不满足设置的条件时自动将bug提交到Mercury的产品 Quality Center中去。(演示略) ONLY FOR SJCU Presentation 流程 6. View Results演示–阅读测试报告 Refer to report ONLY FOR SJCU Presentation Winrunner 检查点 Checkpoint • You can use GUI checkpoints in your test scripts to help you examine GUI objects in your application and detect defects. For example, you can check that when a specific dialog box opens, the OK, Cancel, and Help buttons are enabled. • You point to GUI objects and choose the properties you want WinRunner to check. You can check the default properties recommended by WinRunner, or you can specify which properties to check. Information about the GUI objects and the selected properties is saved in a checklist. WinRunner then captures the current property values for the GUI objects and saves this information as expected results. A GUI checkpoint is automatically inserted into the test script. This checkpoint appears in your test script as an obj_check_gui or a win_check_gui statement. ONLY FOR SJCU Presentation Winrunner 检查点 Checkpoint Detail • Checking a Single Property Value • Checking a Single Object • Checking Two or More Objects in a Window • Checking Bitmap • Checking DB table contents • Checking Synchronization • Refer to Lesson 5 ONLY FOR SJCU Presentation Checkpoint - Understanding GUI Checkpoint Statements • A GUI checkpoint for a single object appears in your script as an obj_check_gui statement. A GUI checkpoint that checks more than one object in a window appears in your script as a win_check_gui statement. Both the obj_check_gui and win_check_gui statements are always associated with a checklist and store expected results in a expected results file. • A checklist lists the objects and properties that need to be checked. For an obj_check_gui statement, the checklist lists only one object. For a win_check_gui statement, a checklist contains a list of all objects to be checked in a window. When you create a GUI checkpoint, you can create a new checklist or use an existing checklist. For information on using an existing checklist, see “Using an Existing GUI Checklist in a GUI Checkpoint” on page 175. • An expected results file contains the expected property values for each object in the checklist. These property values are captured when you create a checkpoint, and can later be updated manually or by running the test in Update mode. For more information, see “Running a Test to Update Expected Results” on page 616. Each time you run the test, the expected property values are compared to the current property values of the objects. ONLY FOR SJCU Presentation Checkpoint - Single Property Value • 1) Choose Insert > GUI Checkpoint > For Single Property. – Analog mode, press the CHECK GUI FOR SINGLE PROPERTY softkey in order to avoid extraneous mouse movements. – The WinRunner window is minimized, the mouse pointer becomes a – pointing hand, and a help window opens on the screen. • 2) Click an object. – The Check Property dialog box opens and shows the default function for the selected object. WinRunner automatically assigns argument values to the function. • 3) You can modify the arguments for the property check. – To modify assigned argument values, choose a value from the Property list. The expected value is updated in the Expected text box. – To choose a different object, click the pointing hand and then click an object in your application. WinRunner automatically assigns new argument values to the function. ONLY FOR SJCU Presentation Checkpoint - Single Object • 1) Choose Insert > GUI Checkpoint > For Object/Window, or click the GUI Checkpoint for Object/Window button on the User toolbar. – If you are recording in Analog mode, press the CHECK GUI FOR OBJECT/WINDOW softkey in order to avoid extraneous mouse movements. Note that you can press the CHECK GUI FOR OBJECT/WINDOW softkey in Context Sensitive mode as well. – The WinRunner window is minimized, the mouse pointer becomes a – pointing hand, and a help window opens on the screen. • 2) Click an object. • 3) WinRunner captures the current value of the property of the GUI object being checked and stores it in the test’s expected results folder. – The WinRunner window is restored and a GUI checkpoint is inserted in the test script as an obj_check_gui statement. ONLY FOR SJCU Presentation Checkpoint - Two or More Objects in a Window • 1) Choose Insert > GUI Checkpoint > For Multiple Objects or click the GUI Checkpoint for Multiple – Objects button on the User toolbar. If you are recording in Analog mode, press the CHECK GUI FOR MULTIPLE OBJECTS softkey in order to avoid extraneous mouse movements. The Create GUI Checkpoint dialog box opens. • 2) Click the Add button. . • 3) To add an object, click it once. • 4) The pointing hand remains active. • 5) Click the right mouse button to stop the selection process and to restore the mouse pointer to its original shape. The Create GUI Checkpoint dialog box reopens. • 6) The Objects pane contains the name of the window and objects included in the GUI checkpoint. ONLY FOR SJCU Presentation Checkpoint - Bitmap • 1) Choose Tools > General Options. The General Options dialog box opens • 2) Click the Run > Settings category in the options pane. The run settings • options are displayed. • 3) Select Capture bitmap on verification failure. • 4) Select Window, Desktop, or Desktop area to indicate what you want to capture when checkpoints fail. • 5) If you select Desktop area, specify the coordinates of the area of the desktop that you want to capture. When you run your test, the captured bitmaps are saved in your test results folder. ONLY FOR SJCU Presentation Checkpoint – DBs Checkpoint • Insert > Database Checkpoint > Runtime Record Check. ONLY FOR SJCU Presentation Checkpoint – DBs Checkpoint • You can create runtime database record checkpoints in order to compare the values displayed in your application during the test run with the corresponding values in the database. • Standard database checkpoints are useful when the expected results can be established before the test run. There are two types of standard database checkpoints: Default and Custom. – default check to check the entire contents of a result set – custom check to check the partial contents, the number of rows, and the number of columns of a result set. ONLY FOR SJCU Presentation Checkpoint – DBs Example • Step 1 # Extract values from GUI objects in application. – button_get_state("First",vFirst); button_get_state("Business",vBusiness); button_get_state("Economy",vEconomy); • Step 2 # Calculate the expected values for the database. – if (vFirst) – expDBval = "1" ; else if (vBusiness) – expDBval = "2" ; else if (vEconomy) – expDBval = "3" ; • Step 3 # Add these calculated values to an edit field to be used in the checkpoint. – set_window("Untitled - Notepad", 1); edit_set("Edit", expDBval); • Step 4 # Create a runtime database record checkpoint using the wizard. – db_record_check("list1.cvr", DVR_ONE_MATCH); ONLY FOR SJCU Presentation Checkpoint – DBs Checkpoint Edit ONLY FOR SJCU Presentation Checkpoint – TSL Connect to DB • 1) Connecting to a Database • The db_connect function creates a new database session and establishes a • connection to an ODBC database. This function has the following syntax: • db_connect ( session_name, connection_string ); • The session_name is the logical name of the database session. The connection_string is the connection parameters to the ODBC database. • 2 ) Executing a Query and Creating a Result Set Based on an SQL Statement • The db_execute_query function executes the query based on the SQL • statement and creates a record set. This function has the following syntax: • db_execute_query ( session_name, SQL, record_number ); • The session_name is the logical name of the database session. The SQL is the SQL statement. The record_number is an out parameter returning the number of records in the result set. ONLY FOR SJCU Presentation Checkpoint – TSL Connect to DB • 3) Retrieving Information from the Database • Returning the Value of a Single Field in the Database • The db_get_field_value function returns the value of a single field in the • database. This function has the following syntax: • db_get_field_value ( session_name, row_index, column ); • The session_name is the logical name of the database session. The row_index is the numeric index of the row. (The first row is always numbered “0”.) The column is the name of the field in the column or the numeric index of the column within the database. (The first column is always numbered “0”.) • Returning the Content and Number of Column Headers • The db_get_headers function returns the number of column headers in a query and the content of the column headers, concatenated and delimited by tabs. This function has the following syntax: • db_get_headers ( session_name, header_count, header_content ); • The session_name is the logical name of the database session. The header_count is the number of column headers in the query. The header_content is the column headers, concatenated and delimited by tabs. ONLY FOR SJCU Presentation Checkpoint – TSL Connect to DB • 3) Retrieving Information from the Database • Returning the Row Content • The db_get_row function returns the content of the row, concatenated and • delimited by tabs. This function has the following syntax: • db_get_row ( session_name, row_index, row_content ); • The session_name is the logical name of the database session. The row_index is the numeric index of the row. (The first row is always numbered “0”.) The row_content is the row content as a concatenation of the fields values, delimited by tabs. • Writing the Record Set into a Text File • The db_write_records function writes the record set into a text filedelimited by tabs. This function has the following syntax: • db_write_records ( session_name, output_file [ , headers [ , record_limit ]] ); • The session_name is the logical name of the database session. The output_file is the name of the text file in which the record set is written. The headers is an optional Boolean parameter that will include or exclude the column headers from the record set written into the text file. The record_limit is the maximum number of records in the record set to be written into the text file. A value of NO_LIMIT (the default value) indicates there is no maximum limit to the number of records in the record set. • Returning the Last Error Message of the Last Operation • The db_get_last_error function returns the last error message of the last ODBC or Data Junction operation. This function has the following syntax: • db_get_last_error ( session_name, error ); • The session_name is the logical name of the database session. The error is the error message. ONLY FOR SJCU Presentation Checkpoint – TSL Connect to DB • 4) Disconnecting from a Database • The db_disconnect function disconnects WinRunner from the database and ends the database session. This function has the following syntax: • db_disconnect ( session_name ); • The session_name is the logical name of the database session. ONLY FOR SJCU Presentation Checkpoint - Checking Synchronization • 1) When Should You Synchronize? – When you run tests, your application may not always respond to input with the same speed. For example, it might take a few seconds: – to retrieve information from a database – for a window to pop up – for a progress bar to reach 100% – for a status message to appear WinRunner waits a set time interval for an application to respond to input. The default wait interval is up to 10 seconds. If the application responds slowly during a test run, WinRunner’s default wait time may not be sufficient, and the test run may unexpectedly fail. Increase the default time that WinRunner waits. To do so, change the value of the Tools > General Options > Run > Settings > Timeout for checkpoints and CS statements option . ONLY FOR SJCU Presentation Checkpoint - Checking Synchronization • 1) Place the cursor at the point where you want to synchronize the test. • 2) Choose Insert > Synchronization Point > For Object/Window Bitmap • 3) Manually change the 1 second wait in the script to a 10 second wait. – The one-second wait that was inserted in the previous step is not long – enough. Find the statement: – obj_wait_bitmap("Insert Done...", "Img1", 1); • Refer to Lesson 4 ONLY FOR SJCU Presentation 回顾  Winrunner 简介  Winrunner 实例演示  Winrunner 测试流程 Winrunner GUI map/Test Case/Step  Winrunner 检查点(Single Property Value/Object/Bitmap/DB/Synchronization) ONLY FOR SJCU Presentation 参考资料  Winrunner 用户手册 Winrunner TSL语言指导 Winrunner 自带代码库  Mercury 网站  Google ….  Practise ONLY FOR SJCU Presentation Q&A
还剩40页未读

继续阅读

下载pdf到电脑,查找使用更方便

pdf的实际排版效果,会与网站的显示效果略有不同!!

需要 10 金币 [ 分享pdf获得金币 ] 0 人已下载

下载pdf

pdf贡献者

1073120207

贡献于2014-12-15

下载需要 10 金币 [金币充值 ]
亲,您也可以通过 分享原创pdf 来获得金币奖励!
下载pdf