Testing Flex 4.5 Applications with HP QuickTest Professional

Testing ADOBE® FLEX® 4.5 Applications with
HP QuickTest Professional
Legal notices
Legal notices
For legal notices, see http://help.adobe.com/en_US/legalnotices/index.html.
Last updated 5/2/2011
iii
Contents
Chapter 1: Working with QuickTest Professional
Introduction to the testing process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Test creation overview
Recording tests
................................................................................................. 3
........................................................................................................ 6
About the testing script
............................................................................................... 7
About operations
..................................................................................................... 9
Using checkpoints
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Using common methods and properties
Playing back Flex tests
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Chapter 2: Advanced Concepts
Working with containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Working with Repeater objects
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Working with data-driven and List-based controls
Troubleshooting
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Limitations of automated testing with Flex
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Last updated 5/2/2011
1
Chapter 1: Working with QuickTest
Professional
Introduction to the testing process
Large, complex applications must be tested to make sure that user interactions do not create run-time exceptions and
that connections to data services are functioning properly.
This document assumes that there are two roles in the testing process: the QA testing professional and the Flex
developer. It assumes that the QA testing professional does not know how to develop applications and does not have
access to the Flex source code, the Flex compiler, or the Flex documentation. The Flex developer, on the other hand,
does not necessarily know how to use a testing tool, such as HP QuickTest Professional (QTP).
Flex documentation for developers includes a set of guidelines for creating testable applications. These guidelines
include instructions on how to compile testable applications, instrument custom components so that they can be
tested, and write applications so that the testing process works more smoothly. For information about the guidelines,
see Using Adobe Flex 4.5.
Before you can test an 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 file is known as the HTML wrapper. You deploy these two files to
any web server, in addition to any externally loaded assets such as images or video files.
Some applications require the use of external resources, such as web services or remote objects, ensure that your web
server can access these resources. For example, an application might call a PHP file on a remote server, like
http://yourserver.com/YourFile.php. Ensure that the PHP file is accessible from your testing server.
You also might be required to add a permissions file to the target server to allow your application to access the server.
The permissions files are called crossdomain.xml files. For more information, ask the Flex developer.
To run a test, you launch QTP and request the HTML wrapper. QTP records the interaction with the application as it
would with any other target type. You should then be able to rerun your tests against the application as long as the web
server remains accessible.
Deploying Flex files
Before you can test the application, deploy the application and it's supporting files to a location that is accessible by
QTP. These files include:
• Application SWF file
• HTML wrapper and wrapper files (the wrapper files can include SWF files, JavaScript files, and other files that
provide support for features such as deep linking and history management)
• RSL SWC files
• Module SWF files
• Helper files such as theme SWC files, style SWF files, and image, video, and sound files
You deploy the application and HTML wrapper file to any location on your HTTP server. You must be able to access
this location from QTP.
Last updated 5/2/2011
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
In some cases, files used by the application are located on a remote server. In this case, ensure that the files are
accessible through any firewalls. Furthermore, the remote servers might need to include cross-domain permission files
to allow remote access. For more information, discuss this with the Flex developer.
If necessary, you can password-protect the HTML wrapper and use the QTP authentication mechanism to access it.
For more information, see the QTP documentation.
About the Flex and AIR add-ins
The Flex support for QTP requires that you install the following add-ins on the testing machine:
• Flex QTP add-in
• AIR QTP add-in
These add-ins provide the necessary communication layer between Flex and AIR applications and QTP. These plugins ensure that Adobe® Flash® Player and the Flex framework can send the appropriate script interactions to QTP
during record mode.
The Flex QTP add-in runs inside QTP. It provides the mechanism for QTP to send script commands to Flash Player
during playback.
The AIR QTP add-in is for testing AIR applications. It runs inside QTP. When testing AIR applications, start QTP
before starting the AIR application.
Selecting add-ins
When starting QTP, you choose which add-ins to use. You can see the available add-ins in QTP’s Add-in Manager. If
you are testing an application, select the Flex add-in. If you are testing an AIR application, select the AIR add-in.
For applications built with Flex, always select the Web add-in in the Add-in Manager, in addition to the Flex add-in.
For AIR applications, you do not need to select the Web add-in.
Only select the add-ins that you need. Do not load more add-ins than are required for your tests.
About the ActiveX browser plug-in
In addition to these QTP add-ins, testing applications in QTP also requires an ActiveX browser plug-in for Microsoft
Internet Explorer 6 or later. This plug-in is installed when you run the Flex QTP batch file.
The browser plug-in is a signed ActiveX plug-in. It uses the Flash Player flash.external.ExternalInterface class and,
therefore, requires the correct security context for flash.external.ExternalInterface to run.
If the SWF file runs from a web server, Flash Player automatically enables flash.external.ExternalInterface. If the SWF
file runs from a local file system, the SWF file must be trusted for flash.external.ExternalInterface to be enabled and for
the browser plug-in to work properly.
If the plug-in experiences problems while loading, the cause is written to the Flash Player debug log file.
About the testing environment
Component names reflect the nature of the component. For example, a button is a Button control in the Flex
programming environment. In the testing environment, the name of each testable control has a prefix which describes
the type of component.
The prefix depends on which application is used to compile the application (AIR or Flex) and which component set
the component belongs to (Halo/MX or Spark). This prevents controls from different types of applications and
different component sets from being confused in your scripts.
Last updated 5/2/2011
2
3
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
The following table describes these prefixes:
QTP Prefix
Description
Example (as it appears in QTP)
Flex
An MX (or Halo) component in a Flex application.
FlexButton
Spark
A Spark component in a Flex application.
SparkButton
AirFlex
An MX (or Halo) component in an AIR application.
AirFlexButton
SparkAir
A Spark component in an AIR application.
SparkAirButton
The functionality of the controls is similar, but they are distinct controls. Spark controls are controls that are from the
newer Spark component set. Controls not using the Spark name are controls that are from the older component set,
MX (or Halo). Some applications use controls from a single component set. Some applications use a combination of
Spark and MX controls. In general, this does not affect your testing.
Most visual Flex components can be scripted in your quality control tests. The most common properties and methods
of these components can be recorded, tested, and played back.
When you create a test for the first time, notice that visual controls are usually referenced inside containers. Not all
containers that are used by Flex programmers are reflected in the testing environment. For example, a set of buttons
might be inside a horizontal group container (or HGroup), but that HGroup control might not show up in the test
script. Restricting the controls in the scripts makes the scripts easier to read and keeps the hierarchies as short as
possible without losing detail.
QTP Object Type Information document
The QTP Object Type Information documents include complete lists of Flex and AIR components that you can test.
These documents are included as XML files in the automation plugin download. You can download this plugin from
the following location:
https://www.adobe.com/cfusion/entitlement/index.cfm?e=flex4_automation_plugin
The file names for these documents are:
• TEAFlex.xml
• TEAFlex_AIR.xml
These documents list the testable methods and properties for each component. In general, MX components in these
documents are prefaced with the term “Flex”. For example, FlexButton refers to the mx.control.Button control. Spark
components are prefaced with “Spark”. For example, SparkButton refers to the spark.components.Button control.
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. You should
understand how QTP identifies objects and adds them to the object repository. For more information, see “Identifying
objects” on page 8.
Last updated 5/2/2011
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
To create a narrative for a test, you record a series of operations or events on the test objects. It is important to
understand which events QTP recognizes. For Flex developers who want to add events to the list of supported ones for
each object, see the Using Adobe Flex 4.5.
Most QTP tests use checkpoints to compare output values against known values. Flex supports a subset of the types of
checkpoints that are used in QTP. For more information, see “Using checkpoints” on page 10.
If you encounter problems while testing applications, refer to “Troubleshooting” on page 12. This section describes
error codes and their meanings, and describes some common problems that can occur when using the Flex plug-in
with QTP.
About the QTP object model
Before you create a test, it is important to understand how the object model of QTP and Flex are integrated. The test
object model is a set of object types that QTP uses to represent objects that are used in your application. The test object
model maps the QTP test objects to the Flex objects in your application. For example, a Spark Button control in an
application is recognized as a SparkButton in the QTP object model.
You can see a complete list of Flex objects as they appear in the QTP object module in the QTP Object Type
Information document. This document describes the operations and properties of objects available when testing
applications with QTP.
The QTP test objects store properties and record events during the test. Each object has its own set of properties and
methods that QTP can record. Test objects do not support all events and properties of the Flex objects that they
correspond to. They do support the events that are most commonly associated with users’ gestures.
The object repository is a list of all objects used in the test. To add an object to a test, add it to the object repository. To
remove an object from the test, you remove it from the 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 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. This information includes details
such as what keys were held down when the operation occurred or the index of a selected item in a list.
Not all controls have operations. For example, the FlexRule control (a horizontal or vertical line) does not have
operations. You can still add controls without operations to the object repository and use checkpoints to test object
properties. Other controls without operations, such as the FlexRepeater and FlexDisplayObject controls, are low-level
objects that you generally do not have to interact with for your tests.
Automated testing requires that each component be identifiable by a set of persistent unchanging properties, with one
primary property, automationName, which is human readable and easily associated with its onscreen counterpart.
Collectively, this set of properties is called the automation ID. QTP stores the automation ID in a repository. A change
to a component’s ID results in multiple versions of the object in the repository. Additionally, QA engineers can create
data driven scripts by changing these IDs with IDs from a database.
QTP specifically avoids treating list items as components, because the identifiers for list items can change in an editable
list, and identifiers can repeat (for example, a data grid with rows that have repeating text). Also, creating and or
requiring entries in the repository for list items can create a huge burden for data driven scripts, because you must put
all of your list items in the repository and change many objects in the repository.
More Help topics
“QTP Object Type Information document” on page 3
Last updated 5/2/2011
4
5
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
Storing objects
With QTP, you can record and play back your interaction with the application or you can write the script yourself. It
is generally easier to have QTP record your actions with an application, and then modify that recorded script. During
a recording session, QTP adds the Flex objects that you interact with to the object repository. Otherwise, you would
have to define each object separately before using it in your own script.
When QTP encounters a Flex control during a test, it stores a set of properties that describe that object and stores a
reference to it in the object repository. The definition of the Flex control in the QTP object repository contains enough
information for QTP to map that Flex control (such as the Spark Button) to a test object (such as, SparkButton).
The following example shows an MX Button control in the QTP Repository Editor:
A
B
D
C
A. Test object name B. Test object model class C. Flex properties used to identify this object D. Application hierarchy
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 that is used to identify the object in the scripts. QTP can use one or more of the object’s
properties. The properties might be based on the appearance of the Flex control (such as a Button’s label) or on the
Flex ID of the control.
4 Records operations that you perform on the object by using the appropriate test object method.
When a test runs, QTP stores component properties as name-value pairs. QTP only stores properties that are needed
for identification in the object repository. These properties include id and index. You can use checkpoints, data tables,
and other methods to store and retrieve other object properties. Properties can be the value of a TextInput control’s
text or the color of a Button control’s color.
Last updated 5/2/2011
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
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 Application object. 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. In the MyApp application, for
example, for a Button labeled Submit inside a TabNavigator’s view labeled Change Settings, the hierarchy appears like
the following:
Browser
|
Application ("MyApp")
|
Panel ("Change Settings")
|
Button ("Submit")
In QTP scripts, you use dot-notation syntax to access an object, and a dot separates each level. To refer to the Button,
you use a path like the following:
Browser("Home").FlexApplication("MyApp").FlexPanel("Change Settings").FlexButton("Submit")
For information on how a QTP script shows applications, see “About the testing script” on page 7.
To improve script readability, some Flex containers are omitted from the hierarchy if the container has no impact on
the testing. For example, a TabNavigator container includes other containers such as HBox or Panel. The
TabNavigator container itself does not appear in the hierarchy, although the containers on its individual tabs do.
The application hierarchy is also called the display hierarchy, because it generally represents what you see on the screen
in a tree-based layout. The display hierarchy is not always the same as the automation hierarchy, which is the hierarchy
of objects as they are referred to in the QTP scripts. Sometimes containers that appear onscreen (for example, with a
border or in a window) are part of the display hierarchy, but not part of the automation hierarchy.
In general, if a container does not appear on the screen, it does not appear in the testing hierarchy. For example, a
stand-alone HGroup container is often used to lay out content. The HGroup container has no visual representation
and does not generally appear in the test scripts. The exception to this is when the container is a child of TabNavigator.
In this case, the container helps to uniquely identify its contents, and therefore it is part of the hierarchy. For more
information about using the TabNavigator and other containers, see “Working with containers” on page 12.
Recording tests
To record a test in QTP, you must have a compiled application SWF file and 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 or the developer can write the HTML wrapper,
or the developer can generate it with the compiler.
You point QTP to the wrapper file that embeds the application SWF file.
To record a test, you either specify that QTP runs the test on the currently open browser or specify the location of the
application as a URL. In the second case, QTP launches the browser and passes it the request URL that you specified.
You determine which method to use in the Record and Run Settings dialog box.
In general, use a web server to serve the HTML wrapper to the QTP client. Do not request the HTML wrapper file on
the file system.
Last updated 5/2/2011
6
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
To have QTP run the test on an application that is currently running in an open browser window, select the Record
And Run Test On Any Open Browser option. To have QTP open a browser and request a URL, select the second
option, as the following example shows:
When you play back the test, QTP opens the browser and requests the same URL.
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 one view, and QTP updates the other one. For example, if you remove a step in the Expert View,
QTP removes the step from the Keyword View. The same is true for adding steps or adding and removing checkpoints.
The Expert View represents each step in the test as an action in VBScript. VBScript uses dot-notation to separate
parent from child objects. Each line ends with an action, followed by parameters that define that action.
The following example shows a mouse click operation in the Expert View:
Browser("Main Page").FlexApplication("MyApp").FlexButton("b2").Click
The Expert View syntax is as follows:
Browser("document_title").FlexApplication("application_name").test_object("name").operation
[parameters]
The document_title property is defined by the <TITLE> tag in the <HEAD> block of an HTML page. For a Flex
application, the default value of the <TITLE> tag in an HTML wrapper is the URL to the MXML file. If page does not
have a title, QTP uses Browser.
The app_name property is the same as the ID property of the SWF file embedded in the HTML page’s <object> tag.
The test_object is the QTP test object that the Flex control corresponds to. For example, an MX Button control’s
QTP test object is FlexButton. This object takes a name property, which is the QTP name for the object as it appears in
the object repository. This name is usually based on its appearance (such as a label), and is sometimes the same as the
Flex id in the Flex MXML source code.
Last updated 5/2/2011
7
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
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 for an operation depend on the type of control that dispatches the event. The
parameters 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 user entered the number 42 in a FlexTextArea object, the Expert View shows a statement similar to
the following example:
Browser("Main Page").FlexApplication("MyApp").FlexTextArea("ta1").Input "42"
If the user selects text in a FlexTextArea object, QTP records a Select operation. This operation takes two commaseparated parameters. The first parameter is the starting character position, and the second parameter is the ending
character position of the selection. If the user selected the first four characters in a FlexTextArea object, the Expert
View shows a statement similar to the following example:
Browser("Main Page").FlexApplication("MyApp").FlexTextArea("ta1").Select 0,3
Identifying objects
Test objects are the building blocks of the test scripts in QTP. Each object used in the test is stored in the object
repository. Flex controls are mapped to these QTP test objects.
When you record a test, QTP adds each object that you interact with to the object repository. QTP references that
object by its test object name in the script. The identifier that QTP uses is the name property of the test object in the
repository. This property is sometimes the same as the Flex id that the Flex developer specifies in the Flex application
source code. For example, a ComboBox control with a Flex id of "myCombo" is stored in the object repository with the
name myCombo. In QTP scripts, you reference it as the following example shows:
FlexComboBox("myCombo")
However, Flex objects are not always identified in the script by their Flex id properties. In many cases, the test object
name matches what you see on the screen. The QTP test object name of a FlexButton object, for example, is the value
of the label property of the object and not the id property. For example, the following FlexButton is identified in QTP
object repository as “Click Me”:
In the QTP expert view, you refer to that FlexButton object as the following example shows:
FlexButton("Click Me")
If the FlexButton object has no label, QTP uses the ToolTip of the MX 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. Other objects whose test
object names are not the same as the Flex id properties include FlexAccordionHeader, FlexButtonBarButton,
FlexCheckBox, FlexLink, FlexPopUpButton, FlexRadioButton, FlexScrollThumb, FlexSimpleButton,
FlexSliderThumb, and FlexTab.
Last updated 5/2/2011
8
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
About operations
When you interact with an application while recording, your actions are stored in the QTP script. These actions, such
as clicking a button, define the narrative of the test script. They are known in QTP as operations. In Flex, they are
known as events. Each operation defines an interaction with a control in the application. You generally use a
combination of operations to perform complex interactions with applications. These operations include filling out a
form and submitting it, or dragging several objects and dropping them in a particular location.
Flex controls such as button define many events. These events include common ones like click, showToolTip, and
focusIn. They also include events that are rarely or never invoked directly by user interaction, such as
creationComplete, render, and invalid. Flex controls also dispatch events that are more granular than necessary
for most testing, including mouseMove, keyDown, and focusOut.
The most commonly used Flex events are available for use in QTP as operations. However, QTP does not record all
events. QTP records the semantically important gestures, or operations that are logically atomic. For example, when
selecting an item in a ComboBox control, rather than recording the mouseDown, open, drag, mouseUp, and close
event sequence, QTP simply records just the open and select events.
Some events are excluded altogether, but you can manually add them to the playback script. For example, the
FlexApplication object’s mouseMove event is not recorded by default. If it were, the script would include a new step for
every pixel of mouse movement, which would quickly overwhelm the test. You can instruct QTP to play back this event
by adding it manually to the test script. For a list of available operations for each Flex component, see the QTP Object
Type Information document here:
www.adobe.com/go/flex3_qtp_object_type_reference
In some cases, QTP plays back user gestures as a sequence of smaller events. The click event, for example, is played
back as a mouseDown and mouseUp event pair, or keyDown and keyUp, depending on how it was invoked.
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. QTP records
whether events were caused by the mouse or keyboard, as playback can be different for each case. For example, when
a button is clicked using the mouse, the following events are dispatched: mouseDown, mouseUp, and click. However,
if the button was clicked by having the spacebar pressed when the button had focus, the events dispatched are keyDown,
keyUp, and click.
To make the scripts more readable, the Flex plug-in minimizes the number of event parameters recorded in a script.
To reduce recording common information, QTP has a default parameter for each operation. The default value for the
interaction type of an MX Button click is “mouse”. If an operation parameter is the same as its default value, then QTP
does not record it. For example, instead of recording:
FlexButton("buttonId").Click "mouse"
QTP only records:
FlexButton("buttonId").Click
The default action is the mouse click because most of the time a FlexButton click is performed with the mouse and not
the keyboard.
Last updated 5/2/2011
9
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
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.
The Flex QTP plug-in supports the following checkpoint types:
• Bitmap
• Standard
• Table
The Flex QTP plug-in does not support the following checkpoint types:
• Accessibility
• Database
• Image
• Page
• Text
• XML
Standard checkpoints
Standard checkpoints let you examine the properties of controls. You can examine any Flex object in the object
repository. The testable properties include both information about the object’s state (such as a TextArea’s text
property) and information about the object’s appearance (such as the color style property or the height and width
properties).
The available properties are a subset of the Flex control’s full property set, but they include the most commonly used
properties. For a complete list of properties, see the QTP Object Type Information document.
The following example shows part of a script that uses the Check method, which verifies whether the actual value of
an item matches the expected value:
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Support").
FlexForm("index:4").Check CheckPoint("index:4")
For more information, see the QuickTest Professional Object Model Reference.
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),
ensure that your object has focus during the test.
The following example shows the differences among a FlexButton test object with no focus, a FlexButton with focus,
and a FlexButton with the mouse over it:
Last updated 5/2/2011
10
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Working with QuickTest Professional
FlexImage objects never visibly have focus, so this is not a concern if you use a Bitmap Checkpoint for checking images.
Table checkpoints
Table checkpoints let you examine properties in List-based controls and containers. You can use table checkpoints
with all of the Flex List-based controls, which include the List, DataGrid, TileList, and Tree controls. You can also use
table checkpoints with all containers, which generate a list of automationValues for all of the children they contain.
Using common methods and properties
Flex test objects support the methods and properties that are common to all QTP test objects. The following are the
common methods:
• CaptureBitmap
• Check
• CheckProperty
• ChildObjects
• GetROProperty
• GetTOProperty
The following are the common properties:
• Exist
• Object
You can use the common methods and properties in the Keyword or Expert views. The following Expert View example
uses the CheckProperty() method to check whether the visible property of the myList control is set to false:
Browser("My Page").FlexApplication("MyApp").FlexCheckBox("myList").CheckProperty "visible", false
For information about the common methods and properties of all QTP test objects, see the QTP Object Model
Reference.
Playing back Flex tests
To play back a test, you do not need to have the browser open. QTP starts the browser for you. You must have a
generated HTML wrapper that you request from QTP. Do not request the application’s SWF file directly.
In some cases, the playback might not work as expected. This is most often due to synchronization. For example, an
effect can take longer to play back than QTP expects, which means that while the effect is playing, QTP might move to
the next step in the script. Another problem might be if you use asynchronous methods of acquiring data, such as a
web service call. The script continues even if you have not yet received data from a web service operation.
Solutions to these problems include putting in waits or checking if an object exists before continuing. For more
information, see “Resolving playback synchronization issues” on page 14.
Last updated 5/2/2011
11
12
Chapter 2: Advanced Concepts
Working with containers
In general, HP QuickTest Professional (QTP) reduces the amount of detail about nested controls in the testing script.
It removes containers that have no impact on the results of the test or on the identification of the controls from the
script. This applies to containers that are used exclusively for layout, such as the HGroup, VGroup, HBox, VBox, and
Canvas containers, except when they are being used in ViewStack, TabNavigator, or Accordion containers. In these
cases, they are added to the hierarchy to provide navigation.
When using nested containers, be wary of ID conflicts. It is possible for containers with multiple tabs (such as
Accordion and TabNavigator containers) to have the same label on more than one tab. These containers derive their
IDs from the tab labels, therefore, there could be overlapping IDs.
QTP does not record layout containers in the scripts unless you execute an event on that container. This keeps the test
objects from becoming too deeply nested, which makes the testing scripts less readable.
For more information on the application hierarchy, see “About the application hierarchy” on page 6.
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 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.
Working with data-driven and List-based controls
To work properly with automation, a custom item renderer object for a List-based control must be data-driven. For
generating table checkpoints, data is pushed onto a single item renderer, and then values are queried. If an item
renderer is not data-driven, the values generated are incorrect.
If data that is displayed in a List-based control changes across tests, use an index-based approach for recording. Valuebased recording fails in this situation.
Troubleshooting
There are some common problems and resolutions when you use QTP to test your applications. Some common
problems can be resolved by checking the following:
• The developer should use the include-libraries flag to link the automation.swc, automation_agent.swc, and
qtp.swc files into the application when compiling. (You can determine whether these libraries are included or not
by comparing the SWF file sizes with and without the libraries. Applications compiled with these libraries are
larger.)
Last updated 5/2/2011
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Advanced Concepts
• Use the Process Explorer (found at
http://www.microsoft.com/technet/sysinternals/Processesandthreadsutilities.mspx) to find out whether
TEAPluginIE.dll and TEAPluginQTP.dll are loaded. Search for these DLLs once you have started recording. If only
TEAPluginQTP.dll is loaded and TEAPluginIE.dll is not loaded it might be a problem with IE security settings.
TEAPluginIE exposes an ActiveX control that the QTP agent uses.
• View the Flash Player log file. It can be found at C:\Documents and Settings\user_name\Application
Data\Macromedia\Flash Player\Logs where user_name is the current Windows user name. See if there are any error
strings.
General troubleshooting
You can solve other common problems by ensuring the following information about your environment and
application:
• ActiveX version of the debugger version of Flash Player 9 or later is installed.
• Flex or AIR QTP add-ins are installed. In QTP, the available add-ins are listed during startup.
• The application was compiled using Flex 3 or later with the latest frameworks.swc file that supports automated
testing.
• The application is running in Microsoft Internet Explorer version 6 or later.
• The application is loaded through an HTML page (or, wrapper), with an <object> tag that has an id attribute set.
The id attribute contains no periods or hyphens.
• The application is loaded either from a web server or locally from a trusted SWF file.
To determine if you have the correct versions of the required applications, go to the Add or Remove Programs control
panel. Look at the list of currently installed programs.
If QTP does not record interactions with your application, determine if the add-ins and plug-in are installed. The
following problems are the most common:
• Flash Player is not the right version. Version 9 or later is required.
• Internet Explorer is not the right version. Version 6 or later is required.
• Internet Explorer has plug-ins turned off. QTP requires the use of an ActiveX plug-in.
• QTP ActiveX plug-in was not installed (this should have been loaded with the Flex and AIR plug-ins).
• Flex and AIR QTP add-ins were not installed.
• DLLs that the Flex plug-ins are dependent on do not exist in the system. These include MSVCR71.DLL and
MSVCP71.DLL.
You can determine the problem in the following ways:
• View a list of installed add-ins in the QTP Add-ins Manager.
• View the log files. For more information, see “Logging with debugger version of Flash Player” on page 14.
Recording events
When recording events with QTP, you might experience the following issues:
• If QTP does not record any events, be sure that the application was compiled with the automation libraries if you
are not using run-time loading. Ask the Flex developer to recompile the application.
Last updated 5/2/2011
13
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Advanced Concepts
• When clicking on a component, the click event might be recorded on some other component. In this case, the
required component could be been part of a composite object. Either the containing object does not expose its
children properly or the owner property was not set properly.
Logging
To help determine the source of problems, you can view the Flash Player and QTP log files.
Logging with debugger version of Flash Player
Debugger version of Flash Player writes plug-in and ActionScript errors to the flashlog.txt file. The default location of
this file on Windows is C:\Documents and Settings\user_name\Application Data\Macromedia\Flash Player\Logs,
where user_name is the current Windows user.
To enable logging, use the debug version of Flash Player. You might need to configure the mm.cfg file to enable
logging. For more information, see Using Adobe Flex 4.5.
Logging with QTP
You can configure QTP logging to log QTP errors related to application testing. You then view the QTP log file for
possible sources of problems.
Turn on logging of the QTP log file
1 Open a command-line dialog box.
2 Go to the QTP bin directory. The default location is C:\Program Files\HP\QuickTest Professional\bin.
3 For QTP 9.2 and earlier, run MicLogSetting.exe. For QTP 9.5 and later, run ClientLogs.exe. The log settings dialog
box appears.
4 For the QTP options, select LogCatPackTEA and LogCatPackTE from the Available Categories list. Click the right
arrow button to move these categories to the Selected Categories list.
5 For each category, increase the log level. For QTP 9.5 and later, set the Category Level to Debug2.
6 Enter a path where you want your log files to be stored.
7 Click OK to save your changes to the QTP log levels.
8 Run QTP. Record interactions with your application as usual.
9 Close QTP.
10 Examine the QTP log file for potential problems.
QTP generates alog file at the location you specified in the log settings dialog box. To ensure that the plug-in is
running, see if the following appears in the log:
Read Flex environment and matching ProgId TEAPluginQTP.TEAFlexAgentQTP
Note: The QTP log file can be very large. You might want to restrict its use to when you are experiencing errors that you
cannot resolve in other ways.
Resolving playback synchronization issues
In some cases, the playback of a test script is not synchronized with what appears on the screen. For example, QTP
does not wait for effects to finish or for data results to be returned before testing an object. This can result in QTP
recording errors such as the following:
• Your scripts play back inconsistently.
Last updated 5/2/2011
14
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Advanced Concepts
• You experience an “Unspecified Error”.
• Your scripts are failing in a location that should not cause failures.
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").FlexCheckBox("Milk").Click Wait(10)
For more information on using the Wait statements, see the QTP documentation.
Checking if objects exist
You can check if the object exists before executing an operation on that control. To do this, you can use the Exist
statement. The following example checks whether the Milk FlexCheckBox control exists before clicking on it:
If Browser("My Page").FlexApplication("MyApp").FlexCheckBox("Milk").Exist Then
Browser("My Page").FlexApplication("MyApp").FlexCheckBox("Milk").Click
End If
You can also check for the value of the Exist common property on the control. For more information on using the Exist
statement or the Exist common property, see the QTP documentation.
Slowing global playback times
You can configure QTP to play all events slower by setting a global execution delay. This should be considered a last
resort. First, try to insert wait statements before troublesome points in the test, as described in “Adding waits to scripts”
on page 15. In very large testing scripts, increasing the time it takes for each event to fire, even by a fraction of a second,
can dramatically increase the total runtime of the test. Therefore, try to find the lowest possible value that lets your
scripts run correctly.
If you choose to add a global delay, configure QTP to delay each step in your script by some small number of
milliseconds, and then gradually increase this amount until you do not experience errors.
Add a delay to each step in your test
1 Select Tools > Options.
Last updated 5/2/2011
15
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Advanced Concepts
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.
Delaying startup test time
When you change an application, or recompile the application when QTP launches it in the browser, consider delaying
the time that the tests start after the browser launches. If you immediately start a test but the application has not
finished instantiating all of its objects, QTP might record failures.
Delay the start of the test
1 Select Tools > Options.
Last updated 5/2/2011
16
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Advanced Concepts
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 might 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.GetROProperty("width")
a = CInt(actual)
b = CInt(minWidth)
If a > b Then
Msg = "WidthGreaterThan", "Width is greater than: " &minWidth
Reporter.ReportEvent micPass, Msg
Else
Msg = "Width " & actual & " is not greater than " & minWidth
Reporter.ReportEvent micFail, "WidthGreaterThan", Msg
End If
End Function
RegisterUserFunc "FlexButton", "WidthGreaterThan", "WidthGreaterThan"
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Products").
FlexButton("Remove from cart_11").WidthGreaterThan 10
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Products").
FlexButton("Remove from cart_11").WidthGreaterThan 1099
Browser("FlexStore").FlexApplication("flexstore").FlexCanvas("Products").
FlexButton("Remove from cart_11").WidthGreaterThan 100
Last updated 5/2/2011
17
TESTING FLEX 4.5 APPLICATIONS WITH HP QUICKTEST PROFESSIONAL
Advanced Concepts
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.
• Web settings (Tools > Web Event Recording Configuration) do not apply to Flex applications. This is where you
can specify the sensitivity of mouse events (for example, instruct QTP to record a mouseDown and then a mouseUp
operation, rather than a click operation).
• Flex test objects are not in the QuickTest Object Model Reference (Help > QuickTest Professional Help > Contents
tab > QuickTest Object Model Reference). This reference shows all the testable methods and properties, examples,
and a list of identification properties.
You can refer to the QTP Object Type Information documents that describe the Flex and AIR test objects, their
events, and event values. For more information, see “QTP Object Type Information document” on page 3.
Last updated 5/2/2011
18