| Cogitek RIATest 3 Documentation | Copyright © Cogitek Inc. |
Built-in container-type component classes of Flex framework expose their children to the automation framework and so that the children are recognized by an automation tool. This is done in the appropriate automation delegate class of the containing class. As an example of such implementation see ContainerAutomationImpl.as file in Flex SDK.
If you derive a custom class from built-in container-type classes you usually do not need to do anything special to make children of your custom component available for automation since this is done by the automation delegate of base class.
However sometimes you implement a custom component that contains other components but your custom component is not derived from Container built-in class. If that is the case you need to expose components contained in your custom class.
Exposing child components is done by implementing numAutomationChildren/getAutomationChildAt pair of functions. numAutomationChildren function must return the number of children component for your custom class, getAutomationChildAt must return the child at the specified index.
Let us suppose you have a custom component MyBigBox that has an array of children components stored in the property myChildArray. The following code shows how to implement automation delegate for MyBigBox component.
[Mixin]
public class MyBigBoxAutomationImpl extends UIComponentAutomationImpl
{
public static init(root:DisplayObject):void
{
Automation.registerDelegateClass(MyBigBox, MyBigBoxAutomationImpl);
}
public function MyBigBoxAutomationImpl(obj:UIComponent)
{
super(obj);
}
private function get myBigBox():MyBigBox
{
return uiComponent as MyBigBox;
}
override public function get numAutomationChildren():int
{
return myBigBox.myChildArray.length;
}
override public function getAutomationChildAt(index:int):IAutomationObject
{
var child:Object = myBigBox.myChildArray[index];
return child as IAutomationObject;
}
}
Be careful to never return null from getAutomationChildAt function. Doing so will result in runtime exceptions during recording or playback of tests.