FlexMonkey is a new tool to perform automated testing on your Flex applications. With it, you can record a set of interactions, save those commands into a TestCase class, add the TestCase to your TestSuite, and include it as part of a FlexUnit testing workflow.
Unit Testing and Test Driven Development is an encouraged agile method for reducing bugs. Up until now though, Unit Testing has been restricted to testing everything but the User Interface. Sure, we can easily test our functions, utility classes, etc. but the real challenge for the Flash/Flex community has been how to test actual interactivity. I believe that FlexMonkey is on its way to solving this. FlexMonkey incorporates the popular FlexUnit testing framework. Here are some good tutorials to learn more about FlexUnit: Adobe Flex Cookbook
The big question to ask yourself is if you're ready to change your work flow and start writing tests first. Those who practice and advocate TDD (FYI, I'm still learning) will tell you that it changes the way you approach writing code. By writing tests first, it forces you to determine necessary functionality upfront. Cleaner code leads to less bugs. The other huge benefit is that functionality is constantly being tested. If a new feature breaks existing functionality, you will be notified immediately rather than it going undetected until a user finds it.
Steps to set up FlexMonkey.
There are really very few steps to get FlexMonkey up and running.
- Download the latest swc, at the time of writing this its in version .5:
http://code.google.com/p/flexmonkey/ - Copy the FlexMonkeyUI.swc into your projects lib directory.
- Write your first TestCase class. I'm calling mine BaseTestCase and storing it in a test package.
- Add your compiler arguments. These are going to be unique to your system. You'll need to know where your Flex sdk folder is located in order to include the automation swcs. You'll also need to point to your FlexMonkeyUI.swc. The reason for these absolute references is because FlexMonkey does a Mixin to reference the BaseTestCase.
-includes tests.BaseTestCase -include-libraries "/Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/libs/automation_agent.swc" "/Applications/Adobe Flex Builder 3/sdks/3.2.0/frameworks/libs/automation.swc" "/Users/seth/Flex/tutorials/projects/flexMonkey/libs/FlexMonkeyUI.swc" - Write your first test and run!
Click here to see an example (right-click on the example to download the code):
http://9mmedia.com/examples/flexmonkey/
To make FlexMonkey run, click the FlexUnit Runner tab -> Run.
There are circumstances where you'll need to use these properties in your classes:
- automationName: I've used this when there has been a scope conflict - two components with the same id. Even though they live in different classes, the automation only recognizes them by their name. To fix it, I've added their uid to their id name.
- showInAutomationHierarchy: This has also helped with scope conflicts in a ViewStack.
Even though FlexMonkey is only at version .5, I'm already finding it to be a useful tool. When manually testing begins to feel like Groundhog day, its time to automate and make FlexMonkey work.
13 Comments
Thanks! I’ve been looking for something like this for a while .. will definitely give it a try.
Hey,
I try FlexMonkey on your example, it’s awesome,
But does Flex mokey work on a air application?
Mat
Yes, FlexMonkey does work on Air aswell.
the flex moneky windows it launch in a different window or in the window of the application…?
I put in the additional compiler arguments this things:
-include-libraries “…./…/frameworks/libs/automation_agent.swc” “/…./…/frameworks/libs/automation.swc” “…./MonkeyExample/optional/FlexMonkey.swc”
my air app launch but not flexmonkey
Mat – try absolute refs. also point to FlexMonkeyUI.swc.
Also, please use their google group, its a great resource: http://groups.google.com/group/flexmonkey thnx!
Seth,
Thanks for the post!
IMHO, although writing the tests first can be a valuable aid in providing context to the design of an API, it provides far less value for UI design. Although it’s not impossible to do test-first development with FlexMonkey, it is far easier to develop a test after a particular piece of UI functionality has been itself developed.
The big payoff from TDD is the one you mention — preventing code breakage. In summary, I think there’s no shame in writing your tests after you write your code. Shame only comes from not writing tests at all!
Stu Stern
(Founder of the FlexMonkey project)
BTW, I think Mathieu’s problem above is that he’s including FlexMonkey.swc but if he wants the window, he needs to include FlexMonkeyUI.swc instead.
I really want to try FlexMonkey, but I’m having build issues and cannot get off the ground. I’m using Eclipse with the Flex plug-in, and the 3.2.0 SDK.
First, here are the compiler arguments for FlexMonkey 0.5:
-locale en_US -includes test.FlexUnitTests -include-libraries “/Applications/Adobe Flex Builder 3/sdks/3.0.0/frameworks/libs/automation_agent.swc” “/Applications/Adobe Flex Builder 3/sdks/3.0.0/frameworks/libs/automation.swc” “/Users/sstern/eclipse/gxesvn/MonkeyExample/libs/FlexMonkeyUI.swc”
Two problems:
A) When I try to build, I get this error:
unable to open ‘/Applications/Adobe Flex Builder 3/sdks/3.0.0/frameworks/libs/automation_agent.swc’
B) The hard-coded project path (“/Users/sstern”) is not going to work for me. I have to check this project in and share it with a team, so I can’t just put in my local project path. How to correct this?
On the first problem, there is an “automation_agent.swc” in the specified path, so I don’t know why it can’t open it. Also, it seems to me that this should be using 3.2.0 and not 3.0.0.
I addressed this by changing the path to “${flexlib}\libs\automation_agent.swc”. So now I get this error instead:
unable to open ‘“C:\Program Files\Adobe\Flex Builder 3 Plug-in\sdks\3.2.0\frameworks\libs\automation_agent.swc”’
Well, this is better. But it’s still not usable. Any ideas?
Argh! After wrestling with that for about two hours, the problem just magically went away. What happened was I first decided to try adding -include-libraries “${flexlib}\libs\automation_agent.swc” to a new project.
That built, and so I reimported the FlexMonkey project and made the same changes. And then it built.
I’d be tempted to chalk it up to user error, except that Eclipse reported the correct path in the error, and automation_agent.swc was in fact there. So I’ll chalk it up to these tools being buggy.
Below are my current project settings. It still seems very wrong to use an absolute path to FlexMonkeyUI.swc, because this won’t work on other systems.
-locale en_US -includes test.FlexUnitTests -include-libraries “${flexlib}\libs\automation_agent.swc” “${flexlib}\libs\automation.swc” “V:\FlexMonkey\MonkeyExample\libs\FlexMonkeyUI.swc”
Any ideas on how to avoid the absolute path?
Stu, thanks for commenting! Good to hear that writing tests first isn’t a golden rule. I do tend to write stub code first, real code second, and then fill in my stub code with flexMonkey generated code third. Either way, you’re right in that its all about writing tests vs not writing them at all.
Scott, you’re sooo close! Would love to get those absolute paths out aswell.
best, Seth
thank you Stu, it works very well
Hi,
I am trying to capture UI functionality using FlexMonkey. However,
unable
to. The recording agant goes away. Seems navigateToURL is giving
problem. Could you please let me know solution for this.
I am using FlexMonkeyUI.swc. Here’s sample code.
Hi, another FlexMonkey review http://www.testandtry.com/2009/04/07/flexmonkey-flex-test-automation-tool-review/