The automation interfaces and the flow of the automation framework change as you initialize, record, and play back an automatable event.
About the automation interfaces
The Flex class hierarchy includes the following interfaces in the mx.automation.* package that enable automation:
|
Interface
|
Description
|
|
IAutomationClass
|
Defines the interface for a component class descriptor.
|
|
IAutomationEnvironment
|
Provides information about the objects and properties of automatable components needed for communicating with agents.
|
|
IAutomationEventDescriptor
|
Defines the interface for an event descriptor.
|
|
IAutomationManager
|
Defines the interface expected from an AutomationManager by the automation module.
|
|
IAutomationMethodDescriptor
|
Defines the interface for a method descriptor.
|
|
IAutomationObject
|
Defines the interface for a delegate object implementing automation for a component.
|
|
IAutomationObjectHelper
|
Provides helper methods for the IAutomationObject interface.
|
|
IAutomationPropertyDescriptor
|
Describes a property of a test object as well as properties of an event object.
|
About the IAutomationObjectHelper
The IAutomationObjectHelper interface helps the components accomplish the following tasks:
- Replay mouse and keyboard events; the helper generates proper sequence of player level mouse and key events.
- Generate AutomationIDPart for a child: AutomationIDPart would be requested by the Automation for representing a component instance to agents.
- Find a child matching a AutomationIDPart: Automation would request the component to locate a child matching the AutomationIDPart supplied by an agent to it.
- Avoid synchronization issues: Agents invoke methods on Automation requesting operations on components in a sequence. Components may not be ready all the time to perform operations.
For example, an agent can invoke comboBox.Open, comboBox.select "Item1" operations in a sequence. Because it takes time for the drop-down list to open and initialize, it is not possible to run the select operation immediately. You can place a wait request during the open operation execution. The wait request should provide a function for automation, which can be invoked to check the ComboBox control's readiness before invoking the next operation.
Automated testing workflow with the QTP automation tool
Before you automate custom components, you might find it helpful to see the order of events during which Flex's automation framework initializes, records, and plays back events with QTP. You should keep in mind that the QTP adapter class' implementation is only one way to use the automation API for automated testing.
Automated testing initialization
- The user launches the Flex application. Automation initialization code associates component delegate classes with component classes. Component delegate classes implement the IAutomationObject interface.
- AutomationManager is a mixin. Its instance is created in the mixin init() method.
- The SystemManager initializes the application. Component instances and their corresponding delegate instances are created. Delegate instances add event listeners for events of interest.
- QTPAgent class is a mixin. In its init() method, it registers itself for the FlexEvent.APPLICATION_COMPLETE event which is dispatched from the SystemManager. On receiving the event, it creates a QTPAdapter object.
- QTPAdapter sets up the ExternalInterface function map. QTPAdapter loads the QTP Plugin DLLs by creating the ActiveX object to communicate with QTP.
- The QTPAdapter requests the XML environment information from the plugin and passes it to the AutomationManager.
- The XML information is stored in a chain of AutomationClass, AutomationMethodDescriptor, and AutomationPropertyDescriptor objects.
Automated testing recording
- The user clicks the Record button in QTP.
- QTP calls the QTPAdapter.beginRecording() method. QTPAdapter adds a listener for AutomationRecordEvent.RECORD from the AutomationManager.
- The QTPAdapter notifies AutomationManager about this by calling the beginRecording() method. The AutomationManager adds a listener for the AutomationRecordEvent.RECORD event from the SystemManager.
- The user interacts with the application. In this example, suppose the user clicks a Button control.
- The ButtonDelegate.clickEventHandler() method dispatches an AutomationRecordEvent event with the click event and Button instance as properties.
- The AutomationManager record event handler determines which properties of the click event to store, based on the XML environment information. It converts the values into proper type or format. It dispatches the record event.
- The QTPAdapter event handler receives the event. It calls the AutomationManager.createID() method to create the AutomationID object of the button. This object provides a structure for object identification.
The AutomationID structure is an array of AutomationIDParts. An AutomationIDPart is created by using IAutomationObject. (The UIComponent.id, automationName, automationValue, childIndex, and label properties of the Button control are read and stored in the object. The label property is used because the XML information specifies that this property can be used for identification for the Button.)
- The QTPAdapter uses the AutomationManager.getParent() method to get the logical parent of the Button control. The AutomationIDPart objects of parent controls are collected at each level up to the application level.
- All these AutomationIDParts are made part of an AutomationID object.
- The QTPAdapter sends the information in a call to QTP.
- At this point, QTP might call the AutomationManager.getProperties() method to get the property values of the Button control. The property type information and codec that should be used to modify the value format are gotten from the AutomationPropertyDescriptor.
- User stops recording. This is propagated by a call to the QTPAdapter.endRecording() method.
Automated testing playback
- The user clicks the Playback button in QTP.
- The QTPAdapter.findObject() method is called to determine whether the object on which the event has to be played back can be found. The AutomationID object is built from the XML data received. The AutomationManager.resolveIDToSingleObject() method is invoked to see if QTP can find one unique object matching the AutomationID. The AutomationManager.getChildren() method is invoked from application level to find the child object. The IAutomationObject.numAutomationChildren property and the IAutomationObject.getAutomationChildAt() method are used to navigate the application.
- The AutomationManager.isSynchronized() and AutomationManager.isVisible() methods ensure that the object is fully initialized and is visible so that it can receive the event.
- QTP invokes the QTPAdpater.run() method to play back the event. The AutomationManager.replayAutomatableEvent() method is called to replay the event.
- The AutomationMethodDescriptor for the click event on the Button is used to copy the property values (if any).
- The AutomationManager.replayAutomatableEvent() method invokes the IAutomationObject.replayAutomatableEvent() method on the delegate class. The delegate uses the IAutomationObjectHelper.replayMouseEvent() method (or one of the other replay methods, such as replayKeyboardEvent()) to play back the event.
- If there are check points recorded in QTP, the AutomationManager.getProperties() method is invoked to verify the values.