Testing Flex Applications with MercuryQuickTestProfessional ® ™ Adobe Flex 2
© 2007 Adobe Systems Incorporated. All rights reserved. Testing Flex™ Applications with Mercury QuickTest Professional™ If this guide is distributed with software that includes an end-user agreement, this guide, as well as the software described in it, is furnished under license and may be used or copied only in accordance with the terms of such license.
Contents Chapter 1: Working with QuickTest Professional . . . . . . . . . . . . . . 5 Introduction to the testing process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Deploying Flex files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 About the Flex installed testing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 About the testing environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Contents
CHAPTER 1 1 Working with QuickTest Professional This topic describes how to work with Mercury QuickTest Professional™ and Adobe Flex applications. Contents Introduction to the testing process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 Test creation overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Recording tests. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Before you can test a Flex application, a Flex developer compiles a SWF file for you. The developer also provides you with an HTML file that embeds the SWF file in it. This is known as the HTML wrapper. You deploy these two files to any web server. Some Flex applications require the use of external resources, such as web services or remote objects, so you should ensure that your web server can access these resources.
About the Flex installed testing files The Flex support for QTP requires that you install two ActiveX plug-ins on the testing machine. These plug-ins provide the necessary communication layer between Flex and QTP. One plug-in runs inside of QTP, and the other runs inside the browser. The browser plug-in is signed, and is designed to run in Microsoft Internet Explorer 6 on Windows only.
Test creation overview When you record a test, QTP records the lines of the test script correlating to each action that you performed. Each line typically represents an action that you carried out on a component that appears on the screen. Those components are called objects and the actions you perform on them (such as clicking a button) are called operations. The basic building block of a test is the test object. Objects are stored in the QTP object repository.
Operations are actions that you perform on objects. They are equivalent to a Flex event, but are generally at a higher level. For example, when you click on a Button, QTP records a “click” operation. QTP does not record the mouseDown and mouseUp events, which essentially make up the click event. Each operation has one or more arguments that define information about the event.
The following example shows a Flex Button control in the QTP Repository Editor: Application hierarchy Test object name Test object model class Flex properties used to identify this object When you run a test and interact with a Flex control, QTP does the following: 1. Identifies the test object class that your Flex object maps to. 2. Reads the current state of the object and stores its list of description properties and values. 3. Assigns a unique ID to use to identify the object in the scripts.
About the application hierarchy In the object repository, objects are stored in a hierarchy. The root of the hierarchy is the browser. The next element is the Flex application. Under that are the containers and controls that make up the application. In the QTP Object Repository and Keyword View, a tree-like structure represents the levels of containers in the application. In general, the hierarchy follows the way the application appears visually.
Recording tests To record a test in QTP, you must compile the application’s SWF file and generate the HTML wrapper files. The main wrapper file defines the application as an object on the page and embeds it so that Flash Player is invoked when the page is requested. You cannot request the application’s SWF file directly. You can write the HTML wrapper yourself, or generate it with the compiler. You point QTP to the wrapper file that embeds the application SWF file.
When you play back the test, QTP opens the browser and requests the same URL. Be sure to specify an HTML file or other wrapper file type that embeds the application’s SWF file. You should not request the SWF file directly. About the testing script QTP records the test in an object level view called the Keyword View, and a text-only view of steps called the Expert View. You can edit each view, and QTP updates the other one.
The operation property is the event dispatched by the object that QTP records. This property can take zero or more parameters. The number and type of parameters depend on the type of control that is dispatching the event. They can be a key that was held down during the operation, an index of a list entry, or the text entered in a text field. For example, when a user enters characters in a FlexTextArea object, the text that the user entered is shown after the operation.
If the FlexButton object has no label, QTP uses the ToolTip of the Button for the test object name. If there is no label and no ToolTip, QTP uses the source code’s id property. If the Flex developer did not specify an id, QTP uses the index. If you omit all of these, QTP uses its own numbering scheme to identify the object. The ordering of properties to determine the test object name varies depending on the object.
QTP stores a set of parameters for each operation that define aspects of the operation. These parameters include what keys were held down when the mouse was clicked or the X and Y position of the target in a drag and drop operation. Operation parameters also record where the interaction originated —for example, from the keyboard or the mouse. When recording operations on Flex controls, QTP records the way in which the operation is carried out.
Using checkpoints Checkpoints let you examine objects and fail or pass the test based on whether the object contains the value you expected. During the test, QTP compares the current value against the expected value in the checkpoint. If the values do not match, then the test fails. If they do match, the test passes.
Bitmap checkpoints When using Bitmap Checkpoints, ensure that you account for differences in the appearance of Flex objects. These differences can be due to tab focus on a test object or to the object’s reaction to a mouseOver event. If you add a bitmap checkpoint on a region of the application that has an object with focus (and has the halo effect around that object), you must ensure that your object has focus during the test.
You can use the common methods and properties in the Keyword or Expert views. The following example uses the CheckProperty() method to check whether the visible property of the myList control is set to false in Expert View: Browser("My Page").FlexApplication("MyApp").FlexCheckBox("myList"). CheckProperty "visible", false For information about each of these methods and properties, see the QuickTest Professional Object Model Reference.
Working with QuickTest Professional
CHAPTER 2 2 Advanced Concepts This topic describes advanced concepts when using Mercury QuickTest Professional to test Flex applications. Contents Working with containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Working with Repeater objects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 Working with data-driven and List-based controls. . . . . . . . . . . . . . . . . . . . . . . . . . . .
Working with Repeater objects Repeater objects are visible in the QTP object hierarchy and scripts, and contain the child objects that they have created. In an actual Flex application, these child objects are children of the main container and not the Repeater object. In QTP table checkpoints, both models are accounted for; the child objects are visible as children of the container and the Repeater object.
If QTP does not record interactions with your Flex application, you should try to determine if the plug-in is installed. The following problems are the most common: ■ Flash Player is not the right version. ■ Internet Explorer is not the right version. ■ Internet Explorer has plug-ins turned off. ■ Plug-in was not installed. ■ DLLs that the Flex plug-ins are dependent on do not exist in the system. These include MSVCR71.DLL and MSVCP71.DLL.
3. Run MicLogSetting.exe. The MicLogSetting dialog box appears: 4. From the Level drop-down list, select MicLogLevelDebug2 as the level. 5. In the Folder field, select a folder where the log file is saved. 6. From the Available Categories list, select LogCatPackTEA, and click the right arrow button to move it to the Selected Categories list. 7. Click OK to save your changes to the QTP log levels. 8. Run QTP. Record interactions with your Flex application as usual. 9. Close QTP. 10.
■ Your scripts are failing in a spot where they should not be. There are several solutions to these timing issues, which are described in the following sections. Adding waits to scripts You can use the Wait statement to pause a script’s playback for any number of seconds. You pass Wait(num_seconds) as an argument to the operation you want to pause in the script. The following example waits 10 seconds before clicking the Milk FlexCheckBox control: Browser("My Page").FlexApplication("MyApp").
2. In the Options dialog box, select the Run tab. 3. Select the Normal option for the Run mode. This is the default option. 4. Increase the amount of the Delay Each Step Execution By option to some number of milliseconds. The default value is 0. 5. Click OK to save your changes. 6. Rerun your test. If you still experience problems, increase the amount of the delay and rerun the test.
2. In the Options dialog box, select the Web tab: 3. Increase the amount of the Add n Seconds To Page Load Time option to a number large enough to ensure that your application compiles before QTP starts running the test. The default value is 10.
Making a test fail but continue to the end You may encounter situations where you cannot make the test fail or pass from a script and still continue to the end. Specifically, this has been reported for tests that change a formula within a Data Table. To write a QTP method that causes a test to fail but continue to the end, you create a keyword, as the following example shows: Public Function WidthGreaterThan(test_object, minWidth) actual = test_object.
Limitations of automated testing with Flex The Flex integration with QTP includes the following limitations: ■ Flex test objects do not show up in the Object Identification (Tools > Object Identification) dialog box. Therefore, you generally do not configure the way QTP gets an object id or customize which properties QTP stores. You can configure the properties that Flex uses to identify an object in the TEAFlex.xml file.
Advanced Concepts