Enhancing Flash and Flex Automated Tests with Native Object Methods in TestComplete

Author: SmartBear Software
Applies to: TestComplete 9 – 10

TestComplete with the Web module offers powerful features for the Flex application testing area. Teams developing applications for the Apache Flash Platform will benefit from general support for Flex 4.5 - 4.11 in TestComplete and the ability to call native Flex methods from TestComplete automated tests. In some cases, testers need to perform testing or validation actions that could be implemented only by calling native methods of application objects. For example, calling native methods would allow testers to obtain and verify object style attributes, or work with the underlying dataProvider more efficiently.

In practice, you’d call native object methods in the same way you would access native properties — via the FlexObject property. For example:


To view a list of available native methods for an object, you can use the Object Browser or Object Spy:

Object Browser showing native methods of Flex objects

Native methods can also be found via the statement completion pop-up in keyword tests and scripts when you are entering or modifying test commands:

Selecting a native method of a Flex object for a keyword test operation

Code completion for native methods of Flex objects

With the availability of native Flash, Flex and ActionScript object methods, you can now easily solve testing challenges that previously either could not be automated or were automated ineffectively. Below are just a few examples.

Setting insertion point and selection in text boxes

Text selection, insertion and replacement can now be robustly automated using the native setSelection method. This method enables you to select text and set insertion point based on the character positions in the text box instead of resorting to coordinate clicks and drags.

// [JScript]
// Select all text in a text box and replace it with the new text
textInput.FlexObject.setSelection(0, textInput.FlexObject.length);
textInput.Keys("The quick fox jumps over the lazy cat");

// Insert the word "brown" after "quick"
textInput.FlexObject.setSelection(10, 10);
textInput.Keys("brown ");

// Replace the word "cat" with "dog"
textInput.FlexObject.setSelection(40, 43);

Getting and verifying object styles

Those of you who are testing stylized or skinned Flex applications can now determine object style attributes using the getStyle native method. This way you can verify the application look-and-feel as part of your automated tests.

// [JScript]
var fontFamily = button.FlexObject.getStyle("fontFamily");
aqObject.CompareProperty(fontFamily, cmpEqual, "Arial", false);

var fontSize = button.FlexObject.getStyle("fontSize");
aqObject.CompareProperty(fontSize, cmpEqual, 20);

Scrolling objects

When automating objects whose content is too wide and does not fit the display area, you can make use of the scrollToIndex native method to scroll the target object to the needed viewable range.

// [JScript]


Flash and Flex automation possibilities are almost endless with the availability of native object methods and properties. Now you can automate far more different types of operations, cover more testing scenarios by your automated tests and make your tests even more robust. This functionality is available since TestComplete 8.50. Try these and other features, and let us know how it works for you.

We have just made testing a bit more Flexible for you. Happy testing!