Flex Monkey 1.0 GA User Guide

download Flex Monkey 1.0 GA User Guide

of 61

Transcript of Flex Monkey 1.0 GA User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    1/61

    FlexMonkey 1.0 User GuideVersion 1.0: 2/10/2010

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    2/61

    FlexMonkey 1.0 User GuideEric Owens

    Copyright 2010 by Gorilla Logic, Inc.All Rights Reserved

    FlexMonkey 1.0 User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    3/61

    Contents

    ..........................1. Introduction to FlexMonkey 1

    FlexMonkey Capabilities 1

    Recording 1

    Organizing Tests 1

    Assertions

    Playback 1

    Generating ActionScript TestSuites 2

    Testing AIR applications 2

    FlexMonkey Main Windows 2

    FlexMonkey Console 2

    FlexMonkey Target SWF Window 3

    FlexMonkey in the Browser 4

    .....................................2. FlexMonkey Console 6

    Toolbar 6

    Record Button 7

    FlexMonkey 1.0 User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    4/61

    Play Button 7

    Pause Button 7

    Insert TestSuite Button 7

    Insert TestCase Button 8

    Insert Test Button 8

    Insert Verify Button 8Insert Pause Button 8

    Delete Button 8

    Undo Button 9

    Redo Button 9

    Save Button 9

    Monkey Connection Indicator 9

    Command Grid 9

    Test Container Column 10

    Command Column 11

    Command Target Column 11

    Command Args Column 11

    Test Result Column 11

    FlexMonkey 1.0 User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    5/61

    Detail View 12

    .......................................3. Project Properties 13

    Creating a New Project 13

    Opening an Existing Project 13

    Project Properties Window 13

    Test Target SWF 15

    Mode 15

    Target SWF URL 16

    Width

    Height 16

    Use FlashVars 16

    FlashVar Grid 17

    Generated AS3 17

    Source Directory URL 17

    Suites Package Name 17

    .......................................4. FlexMonkey Setup 19

    Load vs. Link 19

    FlexMonkey 1.0 User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    6/61

    Loading: Application.application workarounds 20

    Loading: Relative URL workarounds 21

    Loading: File.applicationDirectory workarounds 21

    Loading: ApplicationDomain-dependent code 21

    Load the application into Target SWF Window 22

    Link FlexMonkey with your application 22

    Run Generated AS3 tests from ANT 23

    ..........................5. FlexMonkey Test Elements 24

    TestSuite 24

    TestSuite Detail View 25

    TestCase 25

    TestCase Detail View 26

    Test 26

    Test Detail View 26

    UIEventMonkeyCommand 27

    UIEventMonkeyCommand Detail View 29

    UIEventMonkeyCommand ActionScript Syntax 29

    FlexMonkey 1.0 User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    7/61

    PauseMonkeyCommand 30

    PauseMonkeyCommand Detail View 30

    PauseMonkeyCommand ActionScript Syntax 31

    VerifyMonkeyCommand

    VerifyMonkeyCommand Wizard

    VerifyMonkeyCommand Detail View 36

    VerifyMonkeyCommand ActionScript Syntax 40

    CallMonkeyCommand 41

    CallMonkeyCommand ActionScript Syntax 41

    .............................................6. Creating Tests 43Recording 43

    Controlling ThinkTime 43

    Adding Pauses 44

    Adding Assertions

    ..............................................7. Test Playback 45

    Understanding Test Results 46

    NOT_RUN 46

    FlexMonkey 1.0 User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    8/61

    PASS 46

    FAIL 47

    ERROR 47

    EMPTY 47

    .............8. AS3 versions of FlexMonkey Tests. 49

    Code Generation Example Project 49

    Generating the Code 50

    Compiling and running from Ant 51

    FlexMonkey 1.0 User Guide

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    9/61

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    10/61

    1. Introduction to FlexMonkey

    FlexMonkey Capabilities

    Built on the Adobe Flex 3 Automation Platform, FlexMonkey is aneasy-to-use tool for testing Adobe Flex and Air applications.

    Recording

    With FlexMonkey, you can run your Flex application, interact with it,and record those interactions. FlexMonkey stores your interactions ina Test folder that you can see and edit in the FlexMonkey Console.

    Organizing Tests

    FlexMonkey allows you to organize your Testfolders into TestCase

    folders, and your TestCase folders into TestSuite folders, in accordancewith XUnit test organization.

    Assertions

    You can add assertions to your FlexMonkey test that check yourapplications response when the test runs. Assertions can check thevalues of a components properties or styles, or you can capture the

    bitmap of a visible component and compare it to actual bitmap whenyour test runs.

    Playback

    Once you have recorded a test and added assertions, FlexMonkey canplay the test, and you can watch as your application is exercised. You

    can playback individual Tests, TestCases, or TestSuites. FlexMonkey

    Introduction to FlexMonkey 1

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    11/61

    has robust result reporting, and when your test run is completed,FlexMonkey allows you to browse the results

    Generating ActionScript TestSuites

    FlexMonkey can generate a Fluint/FlexUnit-compatible Actionscriptversion of your TestSuite that you can run from ANT. When you runfrom ANT, FlexMonkey will create jUnitReport-compatible output thatyou can integrate with other jUnitReports.

    Testing AIR applications

    You can test AIR applications with FlexMonkey, but the Flex 3 AdobeAutomation platform imposes some limitations. Recording andplayback will only work for the main application window and pop-upsfrom there. Sub-windows and their pop-ups are ignored. Also, Filedialogs are ignored.

    Adobe is improving the automation system in Flex 4 to cover sub-windows, and FlexMonkey will support Flex 4 in a future release.

    FlexMonkey Main Windows

    When you use FlexMonkey with a Flex application, it has 1 mainwindow, the FlexMonkey Console, and your application runs in either

    the Target SWF Window or the Browser.

    If you are testing an AIR application, and you have linked FlexMonkeywith the AIR application, youll have the FlexMonkey Console and yourapplication window.

    FlexMonkey Console

    FlexMonkey 1.0 User Guide 2

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    12/61

    All interactive use-modes for FlexMonkey use the FlexMonkey Console

    (Figure 1-1). If you are running FlexMonkey generated Actionscripttests from ANT, you wont use the console. For more details on theFlexMonkey Console, please see Chapter 2: FlexMonkey Console.

    Figure 1-1. The FlexMonkey Console

    FlexMonkey Target SWF Window

    When you run your application directly under FlexMonkey, as opposedto running your application in a Browser, youll see FlexMonkeys

    Target SWF Window (Figure 1-2).

    Introduction to FlexMonkey 3

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    13/61

    Figure 1-2. MonkeyContacts.swf loaded in the Target SWF Window

    FlexMonkey in the Browser

    When you run your application in a Browser, youll need to compile itwith the MonkeyLink and the Adobe Flex Automation Libraries. Thenyoull navigate to your application independently of the FlexMonkeyconsole and once your application is running, the FlexMonkey consolewill communicate with it over the MonkeyLink.

    FlexMonkey 1.0 User Guide 4

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    14/61

    Introduction to FlexMonkey 5

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    15/61

    2. FlexMonkey Console

    The FlexMonkey Console has three parts, the Toolbar, the CommandGrid, and the Detail View (Figure 2-1).

    Figure 2-1. The three parts of the FlexMonkey Console

    Toolbar

    The FlexMonkey Toolbar appears above the Command Grid in theFlexMonkey Console (Figure 2-2).

    FlexMonkey 1.0 User Guide 6

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    16/61

    Figure 2-2. The FlexMonkey Toolbar

    Record Button

    The Record button toggles recording on and off. When recording is on,the center of the button will glow red.

    Play Button

    The Play button toggles playing on and off. When playing is on, thecenter of the button will glow green. Playing must begin at a TestSuite,

    TestCase or Test. While a test is playing, you can stop it by clicking thePlay button, but you will need to select a TestSuite, TestCase, or Testbefore clicking Play again. If you need to pause playing, click the Pausebutton (see next).

    Pause Button

    The Pause button toggles pause on and off. When the monkey isplaying a test, clicking the Pause button will momentarily halt play.When playing is paused, the center of the Pause button will glowyellow, and the center of the Play button will continue to glow green.To stop pausing, just click the Pause button again.

    Insert TestSuite Button

    FlexMonkey Console 7

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    17/61

    The Insert TestSuite button adds a new, empty TestSuite to yourproject. To add a TestSuite, select a row in the Command Grid and

    click the Insert TestSuite button.

    Insert TestCase Button

    The Insert TestCase button adds a new, empty TestCase to yourproject. To add a TestCase, select a row in the Command Grid andclick the Insert TestCase button.

    Insert Test Button

    The Insert Test button adds a new, empty Test to your project. To adda Test, select a row in the Command Grid and click the Insert TestCasebutton.

    Insert Verify Button

    The Insert Verify button adds a new Verify command to your test. AVerify command can contain assertions about the application you aretesting. To add a new Verify command, select a row in a Test and clickthe Insert Verify command button.

    Insert Pause Button

    The Insert Pause button adds a new Pause command to your test. APause command causes a test to wait for a specifed duration beforeproceeding with the next command of the test. To add a new Pausecommand, select a row in a Test and click the Insert Pause button.

    Delete Button

    FlexMonkey 1.0 User Guide 8

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    18/61

    The Delete button removes items from the Command Grid. To deletean item, select it in the Command Grid and click the Delete button.

    Undo Button

    The Undo button undoes the last action taken in the Command Grid.To undo, click the Undo button.

    Redo Button

    The Redo button redoes the last action taken in the Command Grid. Toredo, click the Redo button.

    Save Button

    The Save button saves the TestSuites in the Command Grid to themonkeyTestSuites.xml file in your project directory. To save, click theSave button.

    Monkey Connection IndicatorIf you are using the MonkeyLink, the Browser Connection indicatorwill glow yellow if FlexMonkey does not detect the presence of the link,and it will glow green if it does detect the link. If you are using theTarget SWF Window, the Browser Connection indicator will bedisabled and gray.

    Command Grid

    The FlexMonkey Command Grid appears just below the Toolbar in theFlexMonkey Console (Figure 2-3).

    FlexMonkey Console 9

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    19/61

    Figure 2-3. The FlexMonkey Command Grid

    The Command Grid has 5 columns that show the basic facts about yourTestSuites. A row in the grid can be one of the following:

    TestSuite TestCase

    Test UIEventMonkeyCommand PauseMonkeyCommand VerifyMonkeyCommand

    Test Container Column

    FlexMonkey 1.0 User Guide 10

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    20/61

    If a row is a TestSuite, TestCase, or a Test, the Test Container columndisplays its name.

    Otherwise, the column is left blank.

    Command Column

    If a row is a UIEventMonkeyCommand, the Command column displaysthe name of the command.

    Otherwise, the column is left blank.

    Command Target Column

    If a row is a UIEventMonkeyCommand or a VerifyMonkeyCommand,the Command Target column displays the name of the UIComponentthat is the target for that rows command.

    Otherwise, the column is left blank.

    Command Args Column

    If a row is a PauseMonkeyCommand, the Command Args columndisplays the duration of the pause.

    If a row is a UIEventMonkeyCommand, the Command Args columncontains the arguments that FlexMonkey will send to the AutomationManager to facilitate playback.

    Otherwise, the column is left blank.

    Test Result Column

    FlexMonkey Console 11

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    21/61

    All rows in the Command Grid can display results information. Take alook at Chapter 7: Test Playback for more information on results

    reporting.

    Detail View

    The FlexMonkey Detail View appears just to the right of the CommandGrid in the FlexMonkey Console (Figure x). There is a different detailview for each type of Command Grid row entry. For more informationon each of the Detail Views, please see Chapter 5: FlexMonkey TestElements.

    FlexMonkey 1.0 User Guide 12

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    22/61

    3. Project Properties

    Creating a New Project

    When you use FlexMonkey, you create a project for each Applicationyou want to test. Typically, you will locate this project in the samedirectory as your applications Flex Builder project.

    A FlexMonkey project consists of two files and a directory. The filemonkeyTestSuites.xmlcontains the tests that you create in theFlexMonkey Console. The file monkeyTestProject.xmlcontains yourproject preferences. The directorysnapshots contains the bitmapimages of your applications components that are recorded when youadd assertions to your tests.

    To create a new project, pull down FlexMonkeys File Menu, and select

    New Project. Youll be presented with a Directory browser. Navigateto the directory where you would like to store your project files, andclickSelect.

    Opening an Existing Project

    If youve previously created a FlexMonkey project and would like toopen it, pull down the File menu and select Open Project. Navigate tothe project you would like to open and clickSelect.

    Project Properties Window

    After youve selected a directory for your new FlexMonkey project, theProject Properties Window will appear (Figure 3-1). You can also

    Project Properties 13

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    23/61

    navigate to this window at any time by pulling down FlexMonkeysProject Menu and selectingProperties.

    There are two main sections in the Project Properties, the Test TargetSWF, and the Generated AS3. At the very bottom of the window arethree buttons:

    Apply Cancel OK

    As you make choices and changes to your Project Properties, you canclickApply or OKat anytime to see the effect of the change. Anytimeyou clickApply or OK, your changes are saved to the filemonkeyTestProject.xml in your project directory. When you clickApply, the property values are applied to your project, but the ProjectProperties window remains open. If you clickOK, the property valuesare applied to your project, and the window closes. If you clickCancel,

    or just close the window, any changes you entered since that lastApplywill be ignored.

    FlexMonkey 1.0 User Guide 14

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    24/61

    Figure 3-1. The FlexMonkey Project Properties Window

    Test Target SWFThe Test Target SWF section is allows you to set how the FlexMonkeyConsole will communicate with the application-under-test and, if youchoose to load your application into FlexMonkey, the parameters forthe load.

    Mode

    There are two options when you select Mode:

    Target SWF Window MonkeyLink

    Project Properties 15

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    25/61

    For more information on these choices, please see Chapter 4:FlexMonkey Setup.

    The first option, Target SWF Window, is the load option. If you selectTarget SWF Window, youll have some more options:

    Target SWF URL Width Height Use FlashVars

    FlashVar Grid

    Target SWF URL

    If you are having FlexMonkey load your application for testing, thenyou need to tell the monkey what application swf to load. You can typein an absolute URL, or, if you will be loading your application swf witha file URL, you can clickBrowse and navigate to the application in the

    browse dialog.

    Width

    This property specifies how wide your applications display area shouldbe in pixels.

    Height

    This property specifies how high your applications display area shouldbe in pixels.

    Use FlashVars

    FlexMonkey 1.0 User Guide 16

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    26/61

    If your applications HTML wrapper passes parameters as FlashVars,you will need to specify them in your project properties. Check theUseFlashVars check box, and then add the name-value pairs to theFlashVar Grid below the check box.

    FlashVar Grid

    If youve checked the Use FlashVars check box, you can add name-value pairs to the FlashVar Grid. To add a new pair, click the + buttonand then edit the grid. To remove a previously entered pair, select it in

    the grid and click the - button.

    These name-value pairs are added toApplication.application.parameters and are accessible by yourapplication when it loads.

    Generated AS3

    FlexMonkey can generate an ActionScript version of the TestSuites inthe FlexMonkey Console. The Source Directory and Suites PackageName control aspects of the generation.

    Source Directory URL

    The Source Directory URL is the directory in your filesystem where

    FlexMonkey should put the top-level package folder for yourTestSuites. By convention, this is typically placed just under thesrcfolder in your Flex Builder project directory.

    Suites Package Name

    Project Properties 17

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    27/61

    This is the name of the top-level package folder that will be placed atthe Source Directory URL.

    FlexMonkey 1.0 User Guide 18

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    28/61

    4. FlexMonkey Setup

    There are two ways you can run your application when you useFlexMonkey. You can

    load your application into FlexMonkeys Target SWF Window, link FlexMonkeys MonkeyLink directly into your application.

    Which one you use depends on the requirements of your application

    and your testing needs, but please note that linking is the best practice.

    Load vs. Link

    The most fundamental choice you make when deciding how to runyour application is whether you will load your application intoFlexMonkey or link your application with FlexMonkey. Table 4-1

    below summarizes the requirements and conditions of loading vs.linking.

    Need FlexBuilder Pro

    License

    Mustrecompile

    application-under-test

    RootApplication

    HTMLwrapper

    Load No No FlexMonkey None

    Link Yes Yes Application-under-test

    Application-under-test

    Table 4-1. Load vs. Link

    Loading is the easiest option. You dont need a Flex Builder Pro licenseand you dont need to recompile your application. However, when you

    FlexMonkey Setup

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    29/61

    run your application after loading, you must be aware that yourapplication will not be the root application. Rather, FlexMonkey willbe the root.

    When FlexMonkey is the root, some code in your application may workdifferently than when the application is launched normally, including:

    Calls to Application.application Loading of relative-path URLs AIRs File.applicationDirectory and .applicationStorageDirectory

    HTML wrapper-related code ApplicationDomain-dependent code

    In some cases, there are workarounds for these issues.

    Loading: Application.application workarounds

    When your application uses the ActionScript construct

    Application.application, it will refer to FlexMonkey as the application,not your application.

    If you have access to the application source code, you can modify it toaddress this problem. If you substitute this.parentApplication forApplication.application in your applications source code, you willredirect the access to your applications application.

    One exception is if you use FlashVars to initialize your application.Because FlexMonkeys approach to FlashVars is to add them toFlexMonkeys Application.application.parameters object, so you shouldstill access your FlashVars as

    Application.application.parameters[myVar].

    FlexMonkey 1.0 User Guide 20

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    30/61

    For more information on using FlashVars with FlexMonkey, see thesection on FlashVars.

    Loading: Relative URL workarounds

    If your application loads files with relative paths, it will load themrelative to FlexMonkeys root directory.

    You can try to address this problem by using absolute URLs in yourapplication source, but if the file you are loading is a SWF, you may run

    into problems with Application Domain or Security Domain conflicts.For more information, lookhere.

    Loading: File.applicationDirectory workarounds

    If your application is an AIR application, when your application usesthe ActionScript construct File.applicationDirectory andFile.applicationStorageDirectory, they will point to FlexMonkeys

    directories.

    There are no workarounds currently -- you will need to linkFlexMonkey with your AIRapplication if you use this functionality.

    Loading: ApplicationDomain-dependent code

    When you are loading, FlexMonkey is the parent Application domain.Any class definitions that are included in the parent will be used byyour application. So, for instance, since FlexMonkey is compiled withthe 3.5 SDK, your applications classes will be using the 3.5 classdefinitions.

    To workaround this problem, you can recompile your application withthe 3.5 SDK, or you can recompile FlexMonkey from source.

    FlexMonkey Setup

    http://livedocs.adobe.com/flex/gumbo/html/WS2db454920e96a9e51e63e3d11c0bf619ab-7fe2.htmlhttp://livedocs.adobe.com/flex/gumbo/html/WS2db454920e96a9e51e63e3d11c0bf619ab-7fe2.htmlhttp://livedocs.adobe.com/flex/gumbo/html/WS2db454920e96a9e51e63e3d11c0bf619ab-7fe2.html
  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    31/61

    Load the application into Target SWF Window

    The easiest way to use FlexMonkey is to load your application directlyinto the FlexMonkey Target SWF Window. However, if yourapplication needs to be launched from a Web Server, this mode is notfor you.

    To load your application directly into the FlexMonkey Target SWFWindow, you navigate to the Project Properties Window, and set the

    Communications Mode to Target SWF Window (the default for newprojects). Then, FlexMonkey will display a window where theapplication swf pointed to by the Target SWF URL in the LoadParameters.

    Link FlexMonkey with your application

    You can build the MonkeyLink into your application, and when you runyour application, it will communicate with the FlexMonkey Console torecord and playback tests.

    To link your application with the MonkeyLink, youll need to have FlexBuilder Pro so that you can build a project with the Automationlibraries. Youll also need the automation_monkey.swc available onthe FlexMonkey download site.Be sure to get the automation_monkey.swc that is for your Flex SDKversion. Currently, there are automation_monkey.swcs available for avariety of Flex SDKs. Check MonkeyAccessories on the website for thelatest availability. Once youve found the automation_monkey.swcthat you want, place the automation_monkey.swc in a directory namelibs in your Flex Builder project directory.

    FlexMonkey 1.0 User Guide 22

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    32/61

    Then, in your applications Flex Builder project, inProject Properties/Flex Compiler/Additional compiler arguments, add each of theseinclude-libraries statements:

    -include-libraries "../libs/automation_monkey.swc"-include-libraries "${flexlib}/libs/automation.swc"-include-libraries "${flexlib}/libs/automation_agent.swc"-include-libraries "${flexlib}/libs/automation_dmv.swc"

    Run Generated AS3 tests from ANT

    You can use FlexMonkey to create TestSuites, and then haveFlexMonkey generate ActionScipt versions of your tests. You can thenrun these ActionScript tests in a FlexMonkey Target SWF window, orin a Browser. For more information, please see Chapter 8: AS3Versions of FlexMonkey Tests.

    FlexMonkey Setup

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    33/61

    5. FlexMonkey Test Elements

    Currently, FlexMonkey has the following test elements:

    TestSuite TestCase Test UIEventMonkeyCommand PauseMonkeyCommand

    VerifyMonkeyCommand

    The first three, TestSuite, TestCase, and Test, are the hierarchicalcontainers you can see in the FlexMonkey Console. The last three,UIEventMonkeyCommand, PauseMonkeyCommand, andVerifyMonkeyCommand, are used to build tests.

    TestSuite

    The TestSuite is the highest-level hierarchical container. Typically, youonly have one TestSuite per project, but you can have more. ATestSuite contains 1 or more TestCases.

    The first field in the TestSuite is the overall result of running theTestSuite. This result is calculated based on all of the TestSuites sub-

    results.

    The TestSuite also includes fields which summarize the sub-results,including the number of Errors and the disposition of all theAssertions.

    For more information on FlexMonkeys results calculations, please seeChapter 7: Test Playback.

    FlexMonkey 1.0 User Guide 24

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    34/61

    TestSuite Detail View

    When you select a TestSuite in the FlexMonkey Consoles CommandGrid, the TestSuite Detail View displays the details of the TestSuite(Figure 5-1).

    Figure 5-1. The TestSuite Detail View

    The TestSuite Detail View allows you to edit the Name field and theDescription Field.

    TestCase

    The TestCase is the middle-level hierarchical container. You useTestCases to organize your Tests into logical groups.

    FlexMonkey Test Elements 25

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    35/61

    TestCase Detail View

    When you select a TestCase in the FlexMonkey Consoles CommandGrid, the TestCase Detail View displays the details of the TestCase. TheTestCase Detail View is identical to the TestSuite Detail View.

    Test

    The Test is the lowest-level hierarchical container. A Test contains

    UIEventMonkeyCommands that drive your applications GUI,PauseMonkeyCommands that inject pauses of specific durations intothe flow of UIEventMonkeyCommands, and VerifyMonkeyCommandsthat inject assertions about the state of your application into the flow ofUIEventMonkeyCommands.

    The fields in the Test are nearly identical to the TestSuite and TestCase,but the Test also includes the ThinkTime field.

    ThinkTime determines how long FlexMonkey waits between eachcommand when running tests. For more information on ThinkTime,please see Chapter 6: Creating Tests.

    Test Detail View

    The Test Detail View is nearly identical to the TestSuite and TestCaseDetail Views, but it also displays the Tests Think Time (Figure 5-2).

    The Test Detail View allows you to edit the ThinkTime, as well as theName and Description fields.

    FlexMonkey 1.0 User Guide 26

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    36/61

    Figure 5-2. The Test Detail View

    UIEventMonkeyCommand

    The UIEventMonkeyCommand captures the data FlexMonkey needs toplayback interactions with your applications GUI. Currently, the onlyway to insert a UIEventMonkeyCommand into a Test is by recordingGUI interactions.

    The first field in a UIEventMonkeyCommand is its Error Result. TheError Result has a value only for commands that fail to execute.Commands fail to execute when FlexMonkey encounters a problem intrying to play them back. If a command displays an error, the detailedreason for the error will be in the Error Message field.

    FlexMonkey Test Elements 27

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    37/61

    The rest of the fields in the UIEventMonkeyCommand are divided intotwo main parts, the Command Target Details and the CommandArguments.

    The Command Target Details include

    Target Value Target Property Container Value Container Property.

    The Target Value and Target Property pair are filled in by theFlexMonkey Test Recorder when you record an interaction with yourapplications GUI. They identify the component with which youinteracted. The Target Property is the name of the componentsproperty that is being used to identify the component. The TargetValue is the value of the Target Property.

    Sometimes, the Target Property and Target Value pair are notsufficient to uniquely identify a Target Component. When thishappens, FlexMonkey may play back a UIEventMonkeyCommand on acomponent different from the one you intended.

    You can use the Container Property and Container Value to helpdisambiguate the Target Component. If you find you need to use thesefields, you can choose any component that is in the parent-chain above

    the intended component in the display hierarchy, and fill in a property/value pair for that containing component.

    Currently, you must manually set the Container Property andContainer Value if FlexMonkey has a problem finding the intendedcomponent for a UIEventMonkeyCommand.

    FlexMonkey 1.0 User Guide 28

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    38/61

    UIEventMonkeyCommand Detail View

    When you select a UIEventMonkeyCommand in the FlexMonkey

    Consoles Command Grid, the UIEventMonkeyCommand Detail Viewdisplays the details of the command (Figure 5-3).

    Figure 5.3. The UIEventMonkeyCommand Detail View

    UIEventMonkeyCommand ActionScript Syntax

    The UIEventMonkeyCommand in the generated ActionScript TestCasehas the following constructor syntax:

    FlexMonkey Test Elements 29

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    39/61

    new UIEventMonkeyCommand(commandName:String,targetValue:String,targetProperty:String,containerValue:String = null,containerProperty:String = null,commandArguments:Array)

    PauseMonkeyCommand

    Sometimes, your test needs to wait after a UIEventMonkeyCommandfor the application to respond before proceeding. The

    PauseMonkeyCommand inserts a pause into the flow ofUIEventMonkeyCommands and VerifyMonkeyCommands. TheDuration field specifies the pause in mS.

    PauseMonkeyCommand Detail View

    The only detail available in the PauseMonkeyCommand Detail View isthe Pauses duration in mS (Figure 5-4).

    FlexMonkey 1.0 User Guide 30

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    40/61

    Figure 5-4. The PauseMonkeyCommand Detail View

    PauseMonkeyCommand ActionScript Syntax

    The PauseMonkeyCommand in the generated ActionScript TestCasehas the following constructor syntax:

    new PauseMonkeyCommand(duration:uint)

    VerifyMonkeyCommand

    The VerifyMonkeyCommand allows you to insert assertions into yourtests and have FlexMonkey check these assertions as it plays back yourtests. It is also an alternative to the PauseMonkeyCommand, in that it

    FlexMonkey Test Elements 31

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    41/61

    allows you to cause your test to wait until your application reaches aparticular state before continuing to the next test command.

    FlexMonkey has two main types of assertions:

    Bitmap Property/Style

    The first type of assertion, Bitmap, compares an expected bitmapimage of one of the UI components in your application to the actual

    bitmap image that FlexMonkey encounters when it plays back yourtest. A VerifyMonkeyCommand can contain zero or one Bitmapassertions.

    The second type of assertion, Property/Style, compares an expectedvalue for a property or style attribute of one of the UI components inyour application to the actual value of that property or style thatFlexMonkey encounters when it plays back your test. A

    VerifyMonkeyCommand can contain 0 or more Property/Styleassertions.

    VerifyMonkeyCommand Wizard

    To add a VerifyMonkeyCommand to a Test, click on theInsert VerifyButton. When you do, you invoke the VerifyMonkeyCommand wizard.The wizard will walk you through these steps:

    Take Component Snapshot Select Component Attributes Edit VerifyMonkeyCommand

    The first step is to take a component snapshot. When you take asnapshot, you are selecting a component to be the target of the

    FlexMonkey 1.0 User Guide 32

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    42/61

    VerifyMonkeyCommands assertions. When the wizard is in the TakeSnapshotmode, the FlexMonkeyConsole is unavailable until you eitherselect a component or cancel the snapshot (Figure 5-5).

    Figure 5-5. FlexMonkey Console in Take SnapshotMode

    While in Take Snapshotmode, you can roll your mouse cursor overyour application, and FlexMonkey will outline in red the componentyour cursor is above. If you click the mouse, the outlined componentbecomes the target of the VerifyMonkeyCommand (Figure 5-6).

    FlexMonkey Test Elements 33

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    43/61

    Figure 5-6. Application in Take Snapshotmode

    In addition to making the highlighted component the targetcomponent of the VerifyMonkeyCommand, FlexMonkey also stores acopy of the components current visual state as a bitmap in your

    FlexMonkey projects snapshotdirectory.

    Once you have taken a component snapshot, theVerifyMonkeyCommand pops up the FlexMonkey Spy Window (Figure5-7) and enables you to select Property and Style attributes forassertions.

    FlexMonkey 1.0 User Guide 34

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    44/61

    Figure 5-7. The FlexMonkey Spy Window

    The FlexMonkey Spy Window has two tabs, one that displays propertyattributes and one that displays style attributes. Each of these tabs hasa set of selection controls that makes it easy to find and select just theattributes you want to make assertions about. The attribute grid ineach tab lets you select attributes by checking the box in the far leftcolumn. If you do select an attribute, FlexMonkey transfers its currentvalue as displayed in the Actual column to the Expected column.

    Once you have selected all the property and style attributes you need inyour VerifyMonkeyCommand, click the OKbutton and FlexMonkeytransfers your selected attributes to the VerifyMonkeyCommand DetailView. The VerifyMonkeyCommand Detail View is the final stop of theVerifyMonkeyCommand Wizard.

    FlexMonkey Test Elements 35

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    45/61

    VerifyMonkeyCommand Detail View

    The VerifyMonkeyCommand Detail View displays the details and tools

    required for working with assertions (Figure 5-8).

    Figure 5-8. The VerifyMonkeyCommand Detail View

    FlexMonkey 1.0 User Guide 36

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    46/61

    Along the top of this view is a toolbar that contains 4 tools:

    Take Snapshotbutton

    Retake Snapshotbutton Snapshot Windowbutton Spy Windowbutton

    The Take Snapshotbutton sends FlexMonkey back to Take Snapshotmode and lets you choose a different component as the target of theVerifyMonkeyCommands.

    TheRetake Snapshotbutton captures a new copy of theVerifyMonkeyCommands current visual state as a bitmap. This isuseful if you are using the VerifyMonkeyCommands capability to makebitmap comparisons, and need to update the expected bitmap.

    TheSnapshot Window button displays the expected bitmaprepresentation of your VerifyMonkeyCommands target component,

    and, if available, the actual bitmap that FlexMonkey encountered whenexecuting the VerifyMonkeyCommand during Test playback. Bydefault, when you click theSnapshot Window button FlexMonkeydisplays the window inExpectedmode, and the window shows theexpected bitmap. If you click in the Snapshot Window anywhere buton the expected components bitmap, FlexMonkey toggles the displaytoActualmode and shows the actual bitmap, if available (Figure 5-9).

    FlexMonkey Test Elements 37

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    47/61

    Figure 5-9. Snapshot Window inExpectedandActualmodes

    TheSpy Window button displays the Spy Window and enables you toedit your property and style attribute choices.

    In the main body of the VerifyMonkeyCommands Detail View, the firstform item is a text box where you can enter a description of theVerifyMonkey Command.

    The next group of form items are the Verify Target details. These itemsare similar to the UIEventMonkeyCommands Command TargetDetails. Please refer to that commands description for moreinformation.

    The next form items are the Retry Specification. If you do not checktheEnable Retry the rest of the Retry Specification is disabled. In thiscase, when FlexMonkey plays back the VerifyMonkeyCommand, it willcheck the assertions one time, determine if they pass or fail, and thencontinue the test.

    However, if you do checkEnable Retry, then when FlexMonkey playsback the VerifyMonkeyCommand, it will check the assertions and ifthey pass, it will continue the test. If the assertions do not pass,FlexMonkey will repeatedly check the assertions, waiting aRetry Delay

    FlexMonkey 1.0 User Guide 38

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    48/61

    number of milliseconds between each check. FlexMonkey will checkthe assertions aRetry Attempts number of times before giving up andfailing the VerifyMonkeyCommand. The Total Retry Timeoutfield is

    not editable and indicates the total time (=Retry Delay *RetryAttempts) FlexMonkey will wait before giving up on checking theassertions.

    A VerifyMonkeyCommand with retry enabled is an alternative tospecifying a PauseMonkeyCommand. By inserting aVerifyMonkeyCommand and choosing retry, you can have your testwait until, for instance, your application opens a new window andpopulates it with backend server data.

    Sometimes when you play back a test and your assertions fail, theproblem lies with the assertions expected value and not in theapplication. In those cases, you may want to update the assertionsexpected value with the actual value FlexMonkey encountered at testplayback time. After FlexMonkey has run a test, you can browse

    through your assertions in either the VerifyMonkeyCommand DetailView or the Spy Window. In either view, if FlexMonkey has a failedassertion where expected and actual values are not equal, FlexMonkeymakes it easy to update an expected value to an actual value.FlexMonkey will display a small blue arrow in the grid and if you clickthe arrow, FlexMonkey will update the expected value with the actualvalue (Figure 5-10).

    FlexMonkey Test Elements 39

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    49/61

    Figure 5-10. Updating the expected value with the actual value

    VerifyMonkeyCommand ActionScript Syntax

    The VerifyMonkeyCommand in the generated ActionScript TestCasehas the following constructor syntax:

    FlexMonkey 1.0 User Guide 40

    V if M k C d(d i ti St i

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    50/61

    new VerifyMonkeyCommand(description:String,snapshot:String,targetValue:String,targetProperty:String,

    containerValue:String = null,containerProperty:String = null,verifyBitmap:Boolean,attributes:ArrayCollection,isRetryable:Boolean = false,delay:String=null,attempts:String=null )

    The attributes ArrayCollection is comprised of AttributeVO elements

    that have the following constructor syntax:

    new AttributeVO(attributeName:String,namespaceURI:String = null,attributeType:String, // either property or styleexpectedValue:String)

    CallMonkeyCommand

    The CallMonkeyCommand is only available for use in generatedActionScript TestCases, and must be added to a generated TestCasemanually. It allows you to call an arbitrary function at any pointduring a test.

    CallMonkeyCommand ActionScript Syntax

    The CallMonkeyCommand in the generated ActionScript TestCase hasthe following constructor syntax:

    new CallMonkeyCommand(func:Function)

    A typical use of the CallMonkeyCommand uses a closure:

    FlexMonkey Test Elements 41

    new CallMonkeyCommand(function():void{Application application writeConsole("In

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    51/61

    new CallMonkeyCommand(function():void{Application.application.writeConsole("InTest And Things Are Happening");})

    FlexMonkey 1.0 User Guide 42

    6 C i T

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    52/61

    6. Creating Tests

    You create Tests with FlexMonkey by recording your interactions withyour application, and then adding assertions to those tests with theFlexMonkey Console. You adjust how your tests will be played back byFlexMonkey by adjusting ThinkTime and adding Pauses in the testflow.

    Recording

    To record a test, first select a Test folder or a command row inside aTest. FlexMonkey will only enable theRecordbutton if you aretargeting a Test. If you select a Test folder, FlexMonkey will addrecorded interactions at the beginning of that Test, even if the Test hassome commands in it already. If you select a command row inside aTest, FlexMonkey will add recorded interactions after the command onthat row.

    To begin the actual recording, click theRecordbutton on theFlexMonkey Toolbar and interact with your application. Whenrecording is active, the center of theRecordbutton will glow red.

    As you interact with your application, FlexMonkey adds commands foreach of the interactions to the Command Grid. You can stop recordingat anytime by clicking theRecordbutton again. When you do, thecenter of theRecordbutton will be white again.

    Controlling ThinkTime

    When FlexMonkey plays back your Test, it will wait for a ThinkTimeduration between each command in the test. You can set the

    Creating Tests 43

    ThinkTime for the Test by selecting the Test folder and editing the

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    53/61

    ThinkTime for the Test by selecting the Test folder and editing theThinkTime field in the Test Detail View. ThinkTime duration ismeasured in milliseconds, and it defaults to 500 milliseconds.

    Adding Pauses

    Sometimes a command in your Test will take longer than the TestsThinkTime to complete. For instance, after submitting Logincredentials, your application makes a call to the server to authenticatethe user before displaying the first screen of the application. When this

    happens, youll need to insert a PauseMonkeyCommand into your Testso that when the first command after the pause executes, theapplication will be ready.

    To insert a Pause, select the row in the Command Grid just before therow where you would like to insert the Pause, then click theInsertPause button on the FlexMonkey Toolbar.

    You can edit the pause duration in the PauseMonkeyCommands DetailView. The pause duration is measured in milliseconds, and the defaultpause is 500 milliseconds.

    Adding Assertions

    You can add assertions to your Test by inserting

    VerifyMonkeyCommands into the Test flow. Assertions allow you tocheck that your Application is behaving correctly. For moreinformation on using the VerifyMonkeyCommand, please see Chapter5: FlexMonkey Test Elements.

    FlexMonkey 1.0 User Guide 44

    T t Pl b k

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    54/61

    7. Test Playback

    You can playback:

    a single Test all the Tests in a TestCase all the TestCases in a TestSuite.

    To playback a single Test, select the Test in the Command Grid, andclick thePlay button.

    To playback all the Tests in a TestCase, select the TestCase in theCommand Grid and click thePlay button.

    To playback all the TestCases in a TestSuite, select the TestSuite in theCommand Grid, and click thePlay button.

    While the Test is playing, the arrow in thePlay button will glow green.When the Test is complete, the arrow in thePlay button will return towhite.

    You can pause playback at any time by clicking thePause button.While playback is paused, the || symbol in thePause button will gloworange. To resume playback, click thePause button again. The ||symbol in the Pause button will return to white.

    Currently, FlexMonkey can only begin playback on a Test, TestCase orTestSuite.

    Test Playback 45

    Understanding Test Results

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    55/61

    Understanding Test Results

    FlexMonkey has a number of symbols that it uses to indicate resultsstatus:

    NOT_RUN

    PASS

    FAIL

    ERROR

    EMPTY

    NOT_RUN

    For an assertion in a VerifyMonkeyCommand, this symbol indicatesthat FlexMonkey has not played back this command and checked the

    assertion since the last time its result was reset. FlexMonkey resetsresults when it first opens a project, and when a user-initiated changeis made that effects the validity of a result.

    For an overall result in a VerifyMonkeyCommand, Test, TestCase, orTestSuite, this symbol indicates that FlexMonkey has not checked atleast one of the assertions below.

    PASS

    For an assertion in a VerifyMonkeyCommand, this symbol indicatesthat FlexMonkey has checked the assertion and that it was true.

    FlexMonkey 1.0 User Guide 46

    For an overall result in a VerifyMonkeyCommand, Test, TestCase, or

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    56/61

    y y , , ,TestSuite, this symbol indicates that FlexMonkey has found all theassertions below to be true.

    FAIL

    For an assertion in a VerifyMonkeyCommand, this symbol indicatesthat FlexMonkey has checked the assertion and that it was false.

    For an overall result in a VerifyMonkeyCommand, Test, TestCase, or

    TestSuite, this symbol indicates that FlexMonkey has found at least oneof the assertions below to be false.

    ERROR

    For an overall result in a UIEventMonkeyCommand orVerifyMonkeyCommand, this symbol indicates that FlexMonkeyencountered a problem playing back the command. Details on the

    problem can be found in the commands Error Message field in itsDetail View.

    For an overall result in a Test, TestCase, or TestSuite, this symbolindicates that FlexMonkey has found at least one of theUIEventMonkeyCommands or VerifyMonkeyCommands below to bean Error.

    EMPTY

    For a VerifyMonkeyCommand that has no Property/Style assertionsand does not have its Verify Bitmap check box checked, this symbolindicates that the VerifyMonkeyCommand has no assertions to check.

    Test Playback 47

    For an overall result in a Test, this symbol indicates that there are no

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    57/61

    ycommands to playback in the Test.

    For an overall result in a TestCase or TestSuite, this symbol indicatesthat there are no non-empty Tests below.

    FlexMonkey 1.0 User Guide 48

    8 AS3 versions of FlexMonkey

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    58/61

    8. AS3 versions of FlexMonkey

    Tests.FlexMonkey can record and run tests that interact directly with yourapplication views, allowing quick, easy creation of GUI tests.FlexMonkey can also save your tests as Actionscript test classes,allowing them to be run in Continuous Integration or customized byediting the generated Actionscript.

    Actionscript versions of FlexMonkey tests are run from an Ant buildscript; if you are new to Ant, see http://www.adobe.com/devnet/flex/articles/flex_ant_pt1_03.html for an intro on using Ant withFlexBuilder.

    Code Generation Example Project

    This chapter has an accompanying example, complete with with aFlexMonkey project already set up for you. The project includes a Flexmodule MXML file to package up the compiled test code, and a simpleAnt build script which runs the test and produces a test report. A testsuite has already been created in the FlexMonkey project, so all youneed to do is load the project, change a few settings, generate code,compile, and run.

    This project also includes an Ant task jar file -- monkey-ant-task.jar--that the build script uses to run the tests. The Ant task in the jar file --monkey-test-launcher -- works best with FireFox. In particular, if youwant to have the Ant script open and close Firefox every time you runit, youll need to set the Firefox about:config entrybrowser.session_store.resume_from_crash to be false. To see how tomodify this variable, look here: http://kb.mozillazine.org/About:config

    Test Playback 49

    http://www.adobe.com/devnet/flex/articles/flex_ant_pt1_03.htmlhttp://www.adobe.com/devnet/flex/articles/flex_ant_pt1_03.htmlhttp://kb.mozillazine.org/About:confighttp://kb.mozillazine.org/About:confighttp://www.adobe.com/devnet/flex/articles/flex_ant_pt1_03.htmlhttp://www.adobe.com/devnet/flex/articles/flex_ant_pt1_03.htmlhttp://www.adobe.com/devnet/flex/articles/flex_ant_pt1_03.htmlhttp://www.adobe.com/devnet/flex/articles/flex_ant_pt1_03.html
  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    59/61

    You can download the project as part of the MonkeyAccessories on the Website. ExtractMonkeyContactsExample.zipto your workspace and

    import it as a FlexBuilder project.

    Generating the Code

    Before you generate AS3 versions of your FlexMonkey tests, you need

    to tell FlexMonkey where to save the AS3 source code. InFlexMonkeys Project Properties window, there is a section at thebottom where you specify the TestSuites source directory and the

    TestSuites package name. FlexMonkey does not support relativepaths, so youll need to change Source Directory URL to match yoursystem. For this example, and as a best practice, choose the exampleprojectss src directory:

    Figure 8-1. Changing the Generated Code Parameters

    FlexMonkey 1.0 User Guide 50

    Now that youve specified the Source Directory for your generatedd ll d th Fl M k Fil M d l t G t AS

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    60/61

    code, pull down the FlexMonkey File Menu and select Generate AS3.FlexMonkey generates AS3 versions of your tests and writes them to

    the directory that you specified.

    Figure 8-2. Generating the AS3

    There is a Flex module in the example project,MonkeyContactsCodeGenExampleTestModule.mxml, that referencesthe TestSuite.as you just generated. The Ant script will compile theapplication and the module, and will then run the tests.

    Compiling and running from Ant

    Before you can compile and run your tests as AS3, youll need tomodify the Ant build.properties file found in the example project tomatch your system. Youll need to pay special attention to flex.home,monkey.url, and monkey.launch.app.

    Test Playback 51

    Note that the example project is supplied with anautomation monkey swc built with the Flex 3 5 0 SDK and that the

  • 8/6/2019 Flex Monkey 1.0 GA User Guide

    61/61

    automation_monkey.swc built with the Flex 3.5.0 SDK, and that theflex.home directory set in the Ant build.properties file points to the

    3.5.0 SDK to be compatible with the swc. You can findautomation_monkey.swcs compiled with other Flex SDKs inMonkeyAccessories on the website.

    Once youve set up your build.properties file, you should be able to runthe ant build script to compile the example application, the exampletest module, and then run the tests in the browser.

    When the tests complete, they will export a junit-compatible test reportthat you can review in your browser.

    FlexMonkey 1.0 User Guide 52