Flex Testing with FlexMonkey
Stern first provided an overview of FlexMonkey:
FlexMonkey is an open source Flex application and library that records and plays back user interface interactions and generates replayable test cases that you can run from a continuous integration framework such as Cruise Control.InfoQ followed up by asking how FlexMonkey differers from other Flex testing tools:
FlexMonkey is the only Flex record/playback tool we're aware of that is entirely Flex-based. It requires no browser plug-ins (other than the Flash player of course) or special scripting languages. Recorded user interface scenarios are output as ActionScript source code that is both readable and editable. Tests can even be easily created without using the recording tool, since with the FlexMonkey API it's trivial to specify most user interface interactions directly in ActionScript.Then, Stern discussed licensing:
If you know Flex, you already know 99% of what you need to know to use FlexMonkey, and you can run FlexMonkey anywhere you can run Flex (ie, virtually any platform).
FlexMonkey itself is licensed under the Apache 2 license, which basically means you can modify the source and redistribute it as part of other open source or commercial products. Obviously this means that Gorilla Logic sees more value in giving FlexMonkey away than in trying to sell it as a product!InfoQ asked about the challenges of testing asyncrounous functions:
It should be noted however that FlexMonkey does rely on Adobe's Flex Automation API, which is included with FlexBuilder Pro. FlexBuilder Standard edition includes a trial version of the Automation API that limits the number of replays allowed per launch of an application. You can evaluate FlexMonkey with FlexBuilder Standard edition and then upgrade to Pro later if you find that you need it. We're hopeful that Adobe will add the Automation API to the vast majority of the Flex platform that is already open source, but for now you'll have to bite the bullet on FlexBuilder Pro. Pro does additionally include performance- and memory-profiling, so if you're doing serious enterprise development it can be a useful upgrade in any case.
Every UI event generated by FlexMonkey is asynchronous, and FlexMonkey pauses (by default for 500 milliseconds) before generating each successive event. If you have a long-running database query for example that's triggered by a button press, you can simply increase the time paused after the button event has been issued.InfoQ followed up on how FlexMonkey uses the Flex Automation framework:
Test runner frameworks like FlexUnit also require special handling for async operations. The FlexMonkey API is itself asynchronous, so you need to give your runner some way to know when the test completes. FlexMonkey generates a READY_FOR_VALIDATION event when it is done issuing all events in a test case. In the case of FlexUnit, you use FlexUnit's addAsync method to tell FlexUnit to "wait" for this event before invoking the next test case.
I should also add that although FlexUnit is the only xUnit framework currently integrated directly into FlexMonkey, you can still use FlexMonkey with any other xUnit framework for Flex. Again, FlexMonkey tests are nothing but ActionScript. Additionally, it would be straightforward to generate code and integrate FlexMonkey with any other xUnit framework in the same way we have done for FlexUnit. (Please feel free to volunteer!).
When you run an application that's linked with the Automation API, every UI event, such as a button or mouse click, generates an "automation event" that describes the corresponding UI event. This information contained in the automation event can be fed back into the Automation API to generate a synthetic button click that Flex responds to exactly like the original UI event. As I mentioned before, using the FlexMonkey API, you can additionally create an event that hasn't been previously recorded through the Automation API. We are successfully using FlexMonkey to record and play virtually any Flex UI event including relatively "exotic" operations such as selecting an item from a ComboBox being used as an itemEditor within a DataGrid.Lastly, InfoQ asked what else readers need to know:
Although our open source project is quite new, FlexMonkey is quite stable. It's also quite well documented. Most people should be up and running with it in less than an hour.
You can actually play with FlexMonkey right this second by running the sample application at http://keystone.gorillalogic.com/~sstern/MonkeyContacts.html. If you run this sample, you'll see how easy it is to record and play back UI scenarios, and you can also see what the generated ActionScript looks like.
The project itself lives at http://flexmonkey.googlecode.com. We hope everyone reading this will join our rapidly growing community there!
Brandon Holt, Preston Briggs, Luis Ceze, Mark Oskin May 21, 2015
Kai Kreuzer, Olaf Weinmann May 21, 2015