You can use the classes in the customagent_src.zip file to create a custom agent that records metrics data as a user interacts with an application. For information about creating an agent that records and plays back user interactions, see Creating a replaying agent.
The custom agent in the customagent_src.zip file is the CustomAdapter class. This class calls an HTTPService that writes event data out to a database.
Supporting classes for the CustomAdapter class include:
In addition to these classes, the ZIP file also includes the environment XML file and a utility class that parses that file.
You can also access a RemoteObject from the custom agent that provides user session information. To simplify, this example writes the data out to a trace log rather than to a database.
Follow the step-by-step instructions in this section to create a Flex application that records automation events by using the CustomAdapter class and its supporting files.
You cannot use this custom agent with agents that use different environment information, such as the QTP agent included in the Flex automation feature. So, if you use the agent in this example, do not use QTP to record scripts.
Before you can create an application that uses the automation API to record automatable events, you must do the following:
After you set up your environment, you can edit the CustomAdapter class to record an interaction with a Flex application.
The CustomAdapter class handles the RECORD events in the recordHandler() method. The RECORD event has the following properties:
var obj:IAutomationObject = event.automationObject; var label:String = automationManager.getProperties(obj, ["label"])[0];
for (var i:int = 0; i<event.args.length; i++) {
trace("event.args[" + i + "]: " + event.args[i]);
}
The default version of the CustomAdapter recordHandler() method contains code that writes event information to a database. Follow the steps in this section to simplify that method so that you can run the example without configuring a database. After executing these steps, you can go back and create a database and revert the CustomAdapter class's recordHandler() method.
Simplify the CustomAdapter example
trace("automation name:" + obj.automationName);
trace("event name:" + event.name);
trace("replayable event:" + event.replayableEvent);
trace("event target:" + event.target);
// Arguments to be sent are '#' separated.
var arguments:String = event.args.join("#");
trace("args:" + arguments);
// Show all event args.
for (var i:int = 0; i<event.args.length; i++) {
trace("event.args[" + i + "]: " + event.args[i]);
}
trace("------------------------");
You can later add the database support by uncommenting the service methods.
trace("in CustomAdapter constructor")
This ensures that the custom agent is being instantiated when the application starts up.
compc -source-path+=c:/myfiles/flex3/agent -include-classes
custom.CustomAdapter custom.CustomAutomationClass
custom.CustomAutomationEventDescriptor
custom.CustomAutomationMethodDescriptor
custom.CustomAutomationPropertyDescriptor
custom.CustomEnvironment
custom.utilities.EnvXMLParser
-library-path+=c:/home/dev/depot/flex/sdk/frameworks/libs
-output=c:/myfiles/flex3/agent/CustomAgent.swc
This creates the CustomAgent.swc file in the c:/myfiles/flex3/agent directory.
Create and run the Flex application
When you use automation with Flex, you must create a Flex application and supporting wrapper files.
<?xml version="1.0"?>
<!-- agent/Main.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" height="100%" width="100%">
<mx:Script><![CDATA[
private function changeLabel(newLabel:String):void {
b1.label = newLabel;
}
]]></mx:Script>
<mx:TextInput id="ti1" text=""/>
<mx:Button id="b1" label="Change Label" click="changeLabel(ti1.text)" />
</mx:Application>
mxmlc -include-libraries+=c:/myfiles/flex3/agent/CustomAgent.swc c:/myfiles/flex3/agent/Main.mxml
This creates Main.swf in the c:/myfiles/flex3/agent directory.
<html><body> <script src="mysource.js"></script> </body></html>
document.write("<object id='tempId' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' height='100%' width='100%'>");
document.write("<param name='src' value='Main.swf'/>");
document.write("<embed name='Main' src='Main.swf' height='100%' width='100%'/>");
document.write("</object>");
The XML file is loaded at run time, so it must accessible by the SWF file on the web server.
http://localhost:8100/flex/agent/index-simple.html
in CustomAdapter constructor automation name:ti1 event name:SelectText event target:[object AutomationManager] args:0#0 event.args[0]: 0 event.args[1]: 0 ------------------------ automation name:ti1 event name:Input event target:[object AutomationManager] args:42 event.args[0]: 42 ------------------------ automation name:Change Label event name:Click event target:[object AutomationManager] args: ------------------------