Adobe
Products
Acrobat
Creative Cloud
Creative Suite
Digital Marketing Suite
Digital Publishing Suite
Elements
Photoshop
Touch Apps
Student and Teacher Editions
More products
Solutions
Creative tools for business
Digital marketing
Digital media
Education
Financial services
Government
Web Experience Management
More solutions
Learning Help Downloads Company
Buy
Home use for personal and home office
Education for students, educators, and staff
Business for small and medium businesses
Licensing programs for businesses, schools, and government
Special offers
Search
 
Info Sign in
Welcome,
My cart
My orders My Adobe
My Adobe
My orders
My information
My preferences
My products and services
Sign out
Why sign in? Sign in to manage your account and access trial downloads, product extensions, community areas, and more.
Adobe
Products Sections Buy   Search  
Solutions Company
Help Learning
Sign in Sign out My orders My Adobe
Preorder Estimated Availability Date. Your credit card will not be charged until the product is shipped. Estimated availability date is subject to change. Preorder Estimated Availability Date. Your credit card will not be charged until the product is ready to download. Estimated availability date is subject to change.
Qty:
Purchase requires verification of academic eligibility
Subtotal
Review and Checkout
Adobe Developer Connection / Flex Developer Center /

Testing Flex applications with FlexMonkey 1.0

by Eric Owens

Eric Owens
  • gorillalogic.com

Created

13 July 2009

Page tools

Share on Facebook
Share on Twitter
Share on LinkedIn
Bookmark
Print
Flex testing

Requirements

Prerequisite knowledge

A basic knowledge of Adobe Flex 3 will be helpful.

User Level

Intermediate

Sample files

  • flexmonkey_sample.zip (605 KB)

Additional Requirements

FlexMonkey 1.0 Air Installer

  • Download

Without automation, testing the UI components of your Flex application can be tedious and time consuming. Adobe includes an automation framework in Flex to enable developers to create automated tests that operate at the GUI level. FlexMonkey 1.0 is an open source AIR application that leverages the Flex automation framework to record and play back GUI interactions with your Flex application. With FlexMonkey, your tests can drive your application views directly, making it easy to exercise the view components and the logic behind them. Integration with the automation framework is under-the-hood; you don't need to make any changes to your application source or compilation method to use FlexMonkey.

In this article, I'll show you how to get started using FlexMonkey as part of your development flow. FlexMonkey can launch your Flex application in different ways depending on your needs. It can launch your application directly from your Flex Builder project, it can connect to your application running in a browser, or it can be linked into your application. In this article, you'll learn how to launch it directly from your Flex Builder project.

Setting up your first FlexMonkey project

When you install FlexMonkey and start it for the first time, you'll see a Welcome dialog box with instructions on getting started (see Figure 1). Click OK.

The FlexMonkey welcome screen
Figure 1. The FlexMonkey welcome screen

To create your first FlexMonkey project, download and extract this article's sample files and then follow these steps:

  1. Choose File > New Project (see Figure 2).
Creating a new project in FlexMonkey
Figure 2. Creating a new project in FlexMonkey
  1. In the New Project dialog box, select a directory to hold your FlexMonkey project files (see Figure 3). For this example, select the Flex Builder project directory for the sample MonkeyContactsIntroExample project.
  2. Click Select, and FlexMonkey will create files to hold your tests and your project preferences.
The New Project dialog box
Figure 3. The New Project dialog box
  1. In the Project Properties window, specify the target SWF (that is, the SWF file that you want to test). In this case, click Browse and select MonkeyContacts.swf in the bin-debug directory of the project (see Figure 4).

    Note: If the SWF you want to test is remote, you can just type in the URL.

The FlexMonkey Project Properties window
Figure 4. The FlexMonkey Project Properties window
  1. Leave Use Browser unchecked, and click Apply. A window will open displaying the target SWF (see Figure 5).
The target SWF window opens on your desktop
Figure 5. The target SWF window opens on your desktop
  1. Adjust the size of the target SWF window using the Project Properties Width and Height settings and click Apply to see the effect.
  2. When you are satisfied with the size of the target SWF window, click OK. (Leave the FlashVars and Generated AS3 Source Directory settings empty for now.)

FlexMonkey will save your project properties, and it will automatically load them the next time you start FlexMonkey.

Creating your first test

After you create a new project, the FlexMonkey Console window opens and you are ready to create your first test (see Figure 6).

The FlexMonkey Console window
Figure 6. The FlexMonkey Console window

Expand NewTestSuite (by clicking the triangle next to it) and then expand NewTestCase to show NewTest (see Figure 7). If you are familiar with xUnit, you will recognize the standard hierarchical test organization in FlexMonkey. Select NewTest by clicking its row. NewTest is Empty because you haven't added any UI commands to it yet. When you select NewTest, the Record button will be enabled. Click the Record button and it glows red to indicate that you are now in Record mode.

The FlexMonkey Console window in Record mode
Figure 7. The FlexMonkey Console window in Record mode

For this example, you will test the Monkey Contact Manager application (see Figure 8); specifically you'll test adding a new contact. While recording is active, every interaction with your application will be recorded by FlexMonkey.

In the MonkeyContacts.swf window, type a new name, select a phone type from the combo box, enter a phone number, leave the birthday field blank, and click Add.

The Contact Manager application to be tested
Figure 8. The Contact Manager application to be tested

When you have finished adding the contact in the MonkeyContacts.swf window, click the Record button again to toggle Record mode off. Figure 9 shows the FlexMonkey console window after recording the new test.

The Console window shows the UI commands that were recorded
Figure 9. The Console window shows the UI commands that were recorded

As you can see, FlexMonkey inserted a sequence of UI commands into NewTest. In the second column, there are entries for Open and Select events, keyboard input, and mouse clicks. In the third column, the id of the target component for the UI command is listed.

In the contact manager application, the id property of the Name field is inName, the id property of the Phone Type field is inType, and the id property of the Phone field is inPhone.

Adding assertions

Now you're ready to add an assertion to your test. With the last command in the test (Click Add) still selected, click the Add Verify button, which is the green check mark in the tool bar. The Take Snapshot dialog box will appear over the FlexMonkey Console window indicating that FlexMonkey is in Snapshot mode (see Figure 10).

FlexMonkey in Snapshot mode
Figure 10 . FlexMonkey in Snapshot mode

While in Snapshot mode, move your mouse cursor over the target SWF window. FlexMonkey highlights the visible Flex components in red to make it easy to select one. Clicking a red-highlighted component makes it the target for your assertions. For this example click the data grid (see Figure 11).

The data grid of the Contact Manager application highlighted in Snapshot mode
Figure 11. The data grid of the Contact Manager application highlighted in Snapshot mode

After you select a target component for your assertions, FlexMonkey displays the Spy window, which shows the current properties and styles for the target component. Click the selectedIndex property, which is currently set to 0 (see Figure 12). Click OK, and FlexMonkey will add an assertion that the selectedIndex property of the data grid will be 0 when the Verify command executes.

The FlexMonkey Spy window
Figure 12. The FlexMonkey Spy window

Back in the FlexMonkey Console window, you can see the added assertion on the right. The detail view for the Verify command shows that the selectedIndex property is expected to be equal to 0 when the command executes (see Figure 13).

The detail view of the Verify command
Figure 13. The detail view of the Verify command

Running your test

Now it's time to have FlexMonkey play back the test. First, select NewTest as shown in Figure 14. Click Play (the button just to the right of the Record button), and FlexMonkey will execute all of the UI commands in NewTest.

Select NewTest and then click Play to run the test
Figure 14. Select NewTest and then click Play to run the test

When FlexMonkey is playing, the Play button will glow green as shown in Figure 15. As FlexMonkey plays, it highlights each UI command in the console window as it is executing. Of course, you can also watch as the commands are executed in the target SWF window.

UI commands are highlighted as they are executed
Figure 15. UI commands are highlighted as they are executed

When FlexMonkey is finished playing the last command of the test, the Play button will stop glowing green and the results for the test will be updated.

FlexMonkey displaying the results of NewTest
Figure 16. FlexMonkey displaying the results of NewTest

Save your work and shut down

You can save your work at any time by clicking the Save button (the blue diskette at the far right of the tool bar). If you don't, and you quit FlexMonkey, you'll be prompted to save your work (see Figure 17).

FlexMonkey prompts you to save changes
Figure 17. FlexMonkey prompts you to save changes

The next time you open FlexMonkey, it will reopen this project, and load the test file and target SWF.

Where to go from here

In this article, I covered setting up a FlexMonkey project, creating tests, adding assertions, and running tests.

I encourage you to play with FlexMonkey on the sample application or on your own Flex application to record and play back UI tests.

You can use the following links and resources to learn more about FlexMonkey:

  • http://flexmonkey.gorillalogic.com
  • gorillalogic.com

Creative Commons License
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License

More Like This

  • Using automated tools across the lifecycle to develop higher quality Flex applications
  • Debugging Flex 4 applications – Part 1: Debugging basics
  • Caltrain Times from design to release: A story of mobile application development
  • Flex Solutions excerpt: Migrating Flex applications onto the desktop with Adobe AIR
  • Flex application testing with RIATest 4
  • Improving Flex application performance using the Flash Player cache
  • Debugging Flex 4 applications – Part 3: Variables view, watchpoints, and Run to Line
  • Debugging Flex 4 applications – Part 2: Breakpoints
  • Load testing Flex applications with NeoLoad
  • Enterprise security for Flex

Tutorials & Samples

Tutorials

  • Flex mobile performance checklist
  • Flex and Maven with Flexmojos – Part 3: Journeyman
  • Migrating Flex 3 applications to Flex 4.5 – Part 4

Samples

  • Twitter Trends
  • Flex 4.5 reference applications
  • Mobile Trader Flex app on Android Market

Flex User Forum

More
07/25/2011 Flash Player Debug Issues - Safari 5.1 & Chrome 13
04/22/2012 Loader png - wrong color values in BitmapData
04/22/2012 HTTPService and crossdomain.xml doesn't work as expected
04/23/2012 Memory related crashes in Flex application

Flex Cookbook

More
04/06/2012 How to detect screen resize with a SkinnableComponent
02/29/2012 Embed Stage3D content inside Flex application components
02/15/2012 Custom WorkFlow Component
02/09/2012 Using Camera with a MediaContainer instead of VideoDisplay

Products

  • Acrobat
  • Creative Cloud
  • Creative Suite
  • Digital Marketing Suite
  • Digital Publishing Suite
  • Elements
  • Mobile Apps
  • Photoshop
  • Touch Apps
  • Student and Teacher Editions

Solutions

  • Digital marketing
  • Digital media
  • Web Experience Management

Industries

  • Education
  • Financial services
  • Government

Help

  • Product help centers
  • Orders and returns
  • Downloading and installing
  • My Adobe

Learning

  • Adobe Developer Connection
  • Adobe TV
  • Training and certification
  • Forums
  • Design Center

Ways to buy

  • For personal and home office
  • For students, educators, and staff
  • For small and medium businesses
  • For businesses, schools, and government
  • Special offers

Downloads

  • Adobe Reader
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player

Company

  • News room
  • Partner programs
  • Corporate social responsibility
  • Career opportunities
  • Investor Relations
  • Events
  • Legal
  • Security
  • Contact Adobe
Choose your region United States (Change)
Choose your region Close

North America

Europe, Middle East and Africa

Asia Pacific

  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States

South America

  • Brasil
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Česká republika
  • Danmark
  • Eastern Europe - English
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • 台灣

Southeast Asia

  • Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam - English

Copyright © 2012 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy Policy and Cookies (Updated)

Ad Choices

Reviewed by TRUSTe: site privacy statement