Effective GUI Test Automation Developing an Automated GUI Testing Tool phần 2

pdf
Số trang Effective GUI Test Automation Developing an Automated GUI Testing Tool phần 2 46 Cỡ tệp Effective GUI Test Automation Developing an Automated GUI Testing Tool phần 2 929 KB Lượt tải Effective GUI Test Automation Developing an Automated GUI Testing Tool phần 2 0 Lượt đọc Effective GUI Test Automation Developing an Automated GUI Testing Tool phần 2 0
Đánh giá Effective GUI Test Automation Developing an Automated GUI Testing Tool phần 2
4.6 ( 18 lượt)
Nhấn vào bên dưới để tải tài liệu
Đang xem trước 10 trên tổng 46 trang, để tải xuống xem đầy đủ hãy nhấn vào bên trên
Chủ đề liên quan

Nội dung

Advantages and Disadvantages of the Commercial Testing Tools 29 ● Testing tools can record quick test scripts at the early stages of the software development life cycle. For example, when a GUI prototype of an application is available, the capture/playback feature can record a test script more smoothly than at the later stage when more modules with bugs are integrated. The test script can be maintained and edited later with more testing functions. ● The testing tools also have test harnesses to manage the automated test scripts. Testers can use the available harnesses to schedule testing executions and manage effective regression testing by reusing the script library. ● In addition, testers can use these tools as learning assistants. Testers can use the tool to learn the properties of different GUI components and learn how to operate different GUI components programmatically. During the process of editing the recorded test scripts, the testers will get familiar with syntax of the script language and structures of the test scripts. An experienced tester discards the capture/playback feature but uses the test script manager in a testing tool. The Common Features of Capture/Playback The capture/playback approach records test scripts by recognizing GUI elements by their ID or by a combination of attribute values. Any change to the attributes will deteriorate the scripts from running. When this happens, the test scripts need to be rerecorded, edited and debugged, and it’s possible that all the testing data created for the previous test scripts would be obsolete. Continually regenerating test scripts is time consuming. Testing tool vendors all claim their tools include the capability of recognizing object-based GUI components. However, testers often find that a tool might recognize GUI objects created within one development environment and not recognize objects created within other environments. The reusability rate of the test scripts recorded by capture/playback is usually low. Some of the tool vendors may offer add-ins to support different development systems. Otherwise, the testers have to purchase various testing tools to meet different testing requirements of a software project. On the other hand, the capture/playback approach assumes the GUI under test can already be functional. When the assumption doesn’t hold, the tester has to abandon the current session of recording and report the problem. After the developers fix the problem, the tester can restart the capture/playback. This process of reporting and fixing may be repeated again and again. When a complete test script is finally recorded for an application, many bugs have been detected during the recording process. The effectiveness of executing the automated test script is limited, but the test script is useful for regression testing. 30 Chapter 2 • Available GUI Testing Tools vs. the Proposed Tool Editing the Recorded Test Script Of the bugs found using the available automated testing effort, most are found during the process of recording the test scripts. The recording process is totally manual. The testers are well aware that recorded test scripts have hard-coded coordinates to locate GUI components. These coordinate values should be removed and changed to recognizable objects. A recorded test script performs actions in exactly the same sequence they were performed during recording. Playing back the raw script will only test whether the actions happen. It doesn’t have code to verify the actions performed by GUI components when users trigger them with keystrokes or a mouse. With GUI testing, you not only need to test whether a GUI component can be manipulated by a mouse click and a keystroke, you must also test whether the desired functions are invoked correctly. The GUI test involves the execution of both GUI and non-GUI components. For example, when a Save button is tested, the test needs to check whether a file is saved and whether the assigned filename is in the correct folder. It also needs to verify whether the contents of the file are consistent. The GUI testing tools normally cannot perform these functions with raw recorded test scripts. Thus, after each session of manual capture/playback, the tool users need to edit the recorded test script to remove the undesired actions performed during recording, change hard-coded testing values and GUI coordinates, and add functions to catch the state of the module changes behind the GUI invocation. Also, testers need to add code to enable the test scripts to predict the consequences of each GUI action and verify the invocation of the other components. Finally, testers learn from the script editing and debugging process, write test scripts by hand, and discard the capture/playback tool. Implementing Testability Hooks One of the reasons the test scripts recorded by the commercial tools fail is that applications are developed with different development environments. There are various types of GUI components. For example, using Microsoft techniques, developers can choose to populate the GUI of an application with .NET, MFC, ActiveX, or third-party GUI components. Java developers can use Java or Java Swing interchangeably. Sometimes the developers assign names or IDs to components. Other times, they just accept the default values assigned by the integrated development environment (IDE). The complexity of the GUI also makes it difficult for the test scripts to work. In defense, tool vendors claim that programmers should be disciplined and stick to the software design specifications. The tool would be able to test the applications if developers added testability hooks in the applications. The developers should insert code to call a test recorder where meaningful operations are implemented. The code would also pass all the parameters needed to re-create the interaction with the capture/playback process. Thus, the development disciplines should comply with the testing tools. The Proposed GUI Testing Approach 31 In the real world, it is impractical to implement testability hooks in applications. Testers want to operate the testing tools independently from operating the application. Developers don’t want a bunch of test code mixed in with the application. They want to develop clean code. Extra code complicates the application and introduces unnecessary bugs. Besides, all software products have undiscovered bugs. Testability hooks in an application will increase the possibility of introducing the bugs in the tools into the application under test. The final result is that these testing tools are often left on the shelf. Reusability for Regression Testing Once a program passes a test script, it is unlikely to fail that test in the future. The test scripts don’t find bugs by testing against one set of testing data. They find bugs by running against different test cases. Testers should spend more time on generating creative testing data and executing the test to cover many branches of the application rather than operating the testing tools to create and debug test scripts. Effective test cases and multiple executions will increase the reusability of the test scripts. Applications are subject to change throughout the software development life cycle. Whenever new lines of code are modified, removed, or added, the changes could adversely affect the performance of the application, so the test scripts need to be rerun. Thus, the recorded test scripts should be made useful for regression testing. The Proposed GUI Testing Approach As you have learned, the available GUI testing tools don’t meet the testing requirements to detect as many bugs as possible. Undetected bugs in software can cause economic losses and sometimes what can seem like disasters to the end users. There is a great need for reliable test technology. In this book, I’ll present GUI testing methods that will actively look for components, generate testing data based on individual GUIs, drive the script generation with the testing data, and execute the test to report bugs. Active GUI Test Approach All the capture/playback-powered testing tools depend on human users to spot GUI components. They then record the actions performed on the GUI components. Today’s testing tools don’t have the capability to see and apply actions to the GUI components before a test script is created. The script and data generation is all passive. Many of the tools are shipped with a test monkey. A test monkey doesn’t understand software applications and performs software testing by applying random mouse and keyboard actions. 32 Chapter 2 • Available GUI Testing Tools vs. the Proposed Tool The Microsoft Visual Studio 6/.NET packages are bundled with a Microsoft Spy++ tool. This tool can spot a GUI component with a mouse movement. But it is handicapped without the capability of applying mouse or key actions. This book will introduce a method to use a hybrid of a test monkey and the Spy++. A tool with the arms of the test monkey and the eyes of Microsoft Spy++ will be able to operate the mouse actions, press the keys, and see the GUI components on the screen. Fortunately, almost all the available testing tools have already been implemented with the capability of translating the mouse and key actions into programs. Once the arms and eyes are implanted into the testing tools, they should be able to write test scripts without the passive capture/playback procedure. Thus, an actively automated test tool can be developed. The approach in this book to developing an active testing tool will be based on the manual testing experiences of an organization. I will begin with testing simple applications to familiarize you with manual and exploratory testing. Then I will use the knowledge gained during the manual and exploratory testing to create test data. Whenever the improved tool encounters a GUI component, it will comprehend the properties of the GUI component and foresee the consequences when a certain action is applied to this GUI component. The properties of the GUI components and the foreseeable consequences will all be stored in a data sheet. This data sheet can be used to drive the execution of the test scripts. Because the test scripts know what the applications are supposed to do, they can be executed to detect bugs when the applications are doing the wrong thing. As the development cycle progresses in this book, we can add new features to the tool. Test script generation will eventually become unattended by human engineers and can be continued day and night. Thus, testers will be freed from recording, editing, and debugging test scripts. They can devote their time to generating test data and executing the scripts to test the application as thoroughly as possible. If some features can not be tested automatically at that time and are high-risk areas, the tester can have more time to manually test these areas. Later the tester can enable the tool with new testing requirements based on the manual testing experience. Generating Testing Data First Each of the available testing tools has its own format for data store. Some less-effective tools can’t read external test cases and their test values are hard-coded in their test scripts. The method described in this book is able to conduct an active survey, so the properties of the GUI components will be collected and saved in a popular data format, such as XML or Microsoft Excel document. Data saved in an XML document is easy to handle and review. Once the GUI information is collected, the tool will be able to understand and predict the GUI behaviors. The tool can use GUI information to generate sequences of testing values and expected outcomes. For example, if the application requires a number as input for a certain The Proposed GUI Testing Approach 33 state, a random number will be automatically assigned into the data store. If a string is needed, the tool will guess a string of text that makes sense to the testers and the developers. If other types of data are required, this tool can initialize appropriate objects of the data type when writing the test script. After the data generation, the tool will be able to provide testers with a chance to view the GUI test cases. Testers can choose to accept the automatically generated test cases or modify the data store immediately. They can also make multiple copies of the data store and assign different values to each test case. It is believed that once the test script executes, it will not find bugs by running against the same test cases. Multiple copies of the data store will enable the scripts to test as many branches of the application as possible, thus maximizing the possibility of finding bugs. Data-Driven Test Scripts All the available testing tools have at lease two features to brag about: one is their capture/ playback capability, the other is their capability for data-driven script generation. However, in real testing projects, the capture/playback feature has often been reported to record lesseffective scripts. Many times, the recorded scripts fail to test the application. The data-driven test script is also on the wish list of tool vendors because many testing tools don’t know how to generate testing data automatically. When they record scripts, they ask the users to enter testing data via a wizard. The wizard doesn’t have the power to automate the process. In other words, data is often generated after test code in the scripts using these tools, and test scripts are not data-driven. In this book, the approach will be to conduct a GUI survey of the application under test. After the survey, the tool will collect the properties of the GUIs in a data store. It will also generate testing values in the store. It will then provide an interface for the testers to view and modify the data. After the testers confirm their satisfaction with the data, the tool will save the data in a data store that is independent of the test scripts. Thus, the test script generation and execution is a data-driven process. GUI invocation is different than invoking a member from a non-GUI component. For example, when a GUI button is clicked, a series of subsequent non-GUI actions can be triggered. It can also cause new windows to appear. To save a file, an application may have a Save button. Clicking the Save button causes a save file dialog box to pop up. You assign a filename to a file folder and click the OK button. For a human user, the task is completed. A test script recorded by conventional tools can perform these actions. But for a manual tester, you need to confirm that the save file dialog box appears after the Save button is clicked. Then you need to verify whether a new filename appears in the folder and whether the content of the new file is as expected. All this is done by comparing the actual results with the expected 34 Chapter 2 • Available GUI Testing Tools vs. the Proposed Tool results. To accomplish the GUI actions and subsequent confirmation and verification, this book proposes an automatic test-scripting process that generates code to achieve the following testing tasks: ● The test script initiates a button click. ● It confirms the expected subsequence. ● It verifies the desired outcome. If any unexpected event happens in one of the three steps, the result reports an error and the test script continues to test the next GUI component. When all the test cases are executed and all three steps are performed, bugs are reported to the developers. Summary The requirement for quicker development and testing cycles for software projects has led to the creation of more effective GUI testing tools. This chapter discussed today’s popular GUI test infrastructure briefly. Many of the GUI testing tasks are still accomplished by manual tests. Test engineers believe that a test monkey is an effective and automated testing tool, but the random actions of test monkeys cannot effectively find many of the bugs. There remains a lot of room for improvement with the currently available GUI testing tools. For example, they lack the automatic generation of testing data and test scripts. This chapter included brief descriptions of some of the GUI testing tools. Most of these tools rely on the capture/playback process to record test scripts. Other tools require testers to write and debug test scripts by hand. These methods of script generation are not effective. The generated scripts are not reliable and become obsolete easily, and it’s expensive to maintain them. I also introduced an active method for GUI survey of an application to improve the current GUI test infrastructure. I then proposed to use the survey result to generate testing data automatically and use the generated data to drive the script execution and to achieve a fully automated testing. The ultimate goal is to dramatically shorten the time required to achieve a higher-quality software application. In my previous book, Effective Software Test Automation: Developing an Automated Software Testing Tool (Sybex 2004), I introduced a tool that achieved testing of non-GUI components of an application with full automation. In that book, full automation means that users feed the testing tool with an application and the automated testing tool delivers a bug report. Continuing with concepts in the previous book, in the upcoming chapters of this book I will discuss methods and approaches to building a tool and accomplishing GUI testing with full automation. Summary 35 The methods of testing GUI components are different than the methods for testing non-GUI components. The techniques involve a discussion of the Win32 API and advanced .NET programming. In Chapter 3 we will develop a C# API Text Viewer to help in the development of a GUI test library throughout the book. The C# API Text Viewer is a GUI-rich application and will also be used under various development stages as the application to be tested manually and automatically by the GUI testing tool. Chapter 4 will start laying out the foundation of the GUI test library. In it, you will be introduced to some useful C#. NET technologies, focusing on GUI testing automation. These GUI testing features will be demonstrated on testing the C# API Text Viewer. You’ll notice that some of the programming techniques introduced in Chapter 5 have already been used in Chapters 3 and 4. If you have written programs in C#, you should not have problems understanding Chapters 3 and 4. Thereafter, in Chapters 6, 7, and 8 we will enable the tool to conduct the first GUI testing with minimum human interaction. The rest of the book will address some specific GUI testing tasks and present methods to expand this tool for more testing capabilities. Chapter 3 C# Win32 API Programming and Test Monkeys 38 Chapter 3 • C# Win32 API Programming and Test Monkeys here are two reasons available testing tools have used a capture/playback facility to record test scripts. One, they don’t have built-in functions that enable them to see GUI component on the screen (as human eyes would). Two, they haven’t been built with a function to apply actions with the mouse and the keyboard (as human hands would). But the tools can “feel” the mouse movements and keystrokes. With the assistance of human eyes and hands to accurately operate the mouse and keyboard, the tools are able to translate that into script languages. Although the script languages don’t have functions that enable them to see GUI components, they have functions that enable them to receive as parameters the objects of the GUI components clicked and the keystrokes pressed and the coordinates of the mouse movement. When a recorded test script is played back, it repeats the actions exactly as seen by human eyes and in the sequence performed by human hands. Thus, one of the differences between programming languages and test script languages is that script languages have built-in functions to move the mouse, click the buttons of the mouse, and press the keys. T This chapter will introduce some applications programming interface (API) programming techniques to provide functions to perform the mouse and key actions. The API programming declares function calls and other data types by accessing functions of the operating system. Usually, an API consists of one or more DLLs that provide some specific functionality. These functions can be used to work with a component, application, or operating system. The API programming usually defines the interface between a high-level language and the lower-level elements of the device drivers of the system. Starting with this chapter, we are going to use C#. NET as the programming language and use the Win32 device drivers of the Microsoft Windows operating system to complete an automated GUI test tool. Based on the requirements of your organization, you can extend the API programming techniques to other languages and platforms. This chapter will also guide you in developing a C#. NET API Text Viewer that will speed up the API programming. Understanding the Custom DLLs After the Microsoft .NET Framework was introduced into the software business, code of the software components has been divided into two categories: managed and unmanaged. The code built with a .NET-aware programming language, such as C#, VB.NET, C++. NET, is in the category of managed code. The code compiled with other compilers is in the category of unmanaged code. Unmanaged code has two types of dynamic link libraries (DLLs). The first is the COMbased DLLs and EXEs. The second is the traditional non-COM-style DLLs and EXEs, or custom DLLs as they are referred to in this chapter.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.