Adobe Flex 3 Help

About the automation APIs

There are four main parts that enable the automation framework in Flex:

  • Core Flex API
  • Automation APIs
  • Agent class (also known as an adapter)
  • Automation tools

The following illustration shows the relationship between these parts:

Automation API diagram.

About the SystemManager class

The SystemManager class is one of the highest level classes in a Flex application. Every Flex application has a SystemManager class. It is the parent of all displayable objects in the application, such as the main mx.core.Application instance and all pop-up windows, ToolTip instances, cursors, and so on.

SystemManager calls the init() method on all mixins. The SystemManager is responsible for creating the AutomationManager class as well as the Agent and the delegate classes. SystemManager is also responsible for adding the Application object to Adobe® Flash® Player or Adobe® AIR™ stage (root).

About the AutomationManager class

The AutomationManager class is a Singleton that extends the EventDispatcher class. It implements the IAutomationManager, IAutomationObjectHelper, and IAutomationMouseSimulator interfaces.

AutomationManager is a mixin, so its init() method is called by the SystemManager class when the application is initialized. In the init() method, the AutomationManager class adds an event listener for the Event.ADDED event. This event is dispatched by Flash Player or AIR whenever a display object is added to the display list. When that happens, Flash Player or AIR calls the childAddedHandler() method:

root.addEventListener(Event.ADDED, childAddedHandler, false, 0, true);

In the childAddedHandler() method, the AutomationManager class:

  • Creates a new instance of a delegate for each display object.
  • Adds the display object to a delegate class map. This maps the display object to a delegate instance; for example:
    Automation.delegateClassMap[componentClass] = Automation.delegateClassMap[className];
    
    

    The delegate class map is a property of the Automation class.

  • Ensures that all children of the new display object are added to the class map as well.

In the recordAutomatableEvent() method, the AutomationManager:

  • Creates an AutomationRecordEvent.RECORD event.
  • Dispatches the RECORD events. The agent listens for these events.

The recordAutomatableEvent() method is called by the delegates.

About the Automation class

During application initialization, the Automation class is created. This is a static class that maintains a map of its delegate class to its component class.

This class does the following for recording events:

  • Provides access to the AutomationManager class
  • Creates delegateClassMap as a static property

For example, there is a MyButton class that extends the Button class, but it does not have its own delegate class (MyButton might not add any new functionality to be recorded or played back). When AutomationManager encounters an instance of the MyButton class, it checks with the Automation class for a corresponding delegate class. When it fails to find one, it uses the getSuperClassName() method to get the super class of the MyButton class, which is the Button class.

AutomationManager then tries to find the delegate for this Button class. At that point, AutomationManager adds a new entry into the delegate-component class for the MyButton class, associating it with the ButtonDelegateAutomationImpl class, so that next time AutomationManager can find this mapping without searching the inheritance hierarchy.

About the delegate classes

The delegate classes provide automation hooks to the Flex framework and charting components. The delegate classes are in the mx.automation.delegates package, and they extend the UIComponentAutomationImpl class. The delegates are named ControlNameAutomationImpl. For example, the Button control's delegate class is ButtonAutomationImpl.

The delegate classes register themselves with their associated Automation class by providing the component class and their own class as input. The AutomationManager class uses the Automation class-to-delegate class map to create a delegate instance that corresponds to a component instance in the childAddedHandler() method.

The delegate classes are mixins, so their init() method is called by the SystemManager class. The init() method of the delegate classes:

  1. Calls the registerDelegateClass() method of the Automation class. This method maps the class to an automation component class; for example:
    var className:String = getQualifiedClassName(compClass);
    delegateClassMap[className] = delegateClass;
    
    
  2. Adds event listeners for the mouse and keyboard events; for example:
    obj.addEventListener(KeyboardEvent.KEY_UP, btnKeyUpHandler, false, EventPriority.DEFAULT+1, true);
    obj.addEventListener(MouseEvent.CLICK, clickHandler, false, EventPriority.DEFAULT+1, true);
    
    

These event handlers call the AutomationManager class recordAutomatableEvent() method, which in turn dispatches the AutomationRecordEvent.RECORD events that the automation agent listens for.

All core framework and charting classes have delegate classes already created. You are not required to create any delegate classes unless you have custom components that dispatch events that you want to automate. In this case, you must create a custom delegate class for inclusion in your Flex application. For more information, see Example: Instrumenting the RandomWalk custom component for QTP.

About the agent

The agent facilitates communication between the Flex application and automation tools such as QTP and Segue.

When recording, the agent class is typically responsible for implementing a persistence mechanism in the automation process. It gets information about events, user sessions, and application properties and typically writes them out to a database, log file, LocalConnection, or some other persistent storage method.

When you create an agent, you compile it and its supporting classes into a SWC file. You then add that SWC file to your Flex application by using the include-libraries command-line compiler option.

The custom agent class must be a mixin, which means that its init() method is called by the SystemManager class. The init() method of the agent:

  • Defines a handler for the RECORD events.
  • Defines the environment. The environment indicates what components and their methods, properties, and events can be recorded with the automation API.

    The sample custom agent class uses an XML file that contains Flex component API information. The agent loads it with a call to the URLRequest() constructor, as the following example shows:

    var myXMLURL:URLRequest = new URLRequest("AutomationGenericEnv.xml");
    myLoader = new URLLoader(myXMLURL);
    automationManager.automationEnvironment = new CustomEnvironment(new XML(source));
    
    

In this example, the source is an XML file that defines the Flex metadata (or environment information). This metadata includes the events and properties of the Flex components.

Note that representing events as XML is agent specific. The general-purpose automation API does not require it, but the XML file makes it easy to adjust the granularity of the events that are recorded.

You are not required to create an instance of your adapter in the init() method. You can also create this instance in the APPLICATION_COMPLETE event handler if your agent requires that the application must be initialized before it is instantiated.

Most agents require a set of classes that handle the way in which the agent persists automation information and defines the environment. For more information, see Creating a recording agent.