Run FlexMonkey Tests from ANT
Like FlexUnit tests I am going to assume a few things:
1) You already have a working understanding of FlexMonkey.
2) You already have a build script set up (or have read the previous posts in this series.
3) You already have a properties file you are using (or setting all the properties directly into the build script.
If you do not know about FlexMonkey, FlexMonkey is:
FlexMonkey is a testing framework for Flex apps that provides for the capture, replay and verification of Flex UI functionality. FlexMonkey can record and playback Flex UI interactions, and generates ActionScript-based testing scripts that can easily be included within a continuous integration process. It uses the Flex Automation API and was created by extending Adobe’s sample automation adapter, AutoQuick.
For more information visit the Flex Monkey Project Home Site.
Unlike FlexUnit where it is run from a pretty little project, FlexMonkey has a lot of moving parts and requires quite a bit of setup. If you are running the automated tests from their AIR application then the process is pretty simple and all you have to do is hit the run button and you get all the information you need immediately.
However, setting up your application to run with FlexMonkey via ANT be prepared for a lot of setup and making sure everything fits just right. What I am really going to highlight here is what files to make sure to have and at what version.
The SDK version that your Application is built with is very important with FlexMonkey. You MUST be building with at least Flex 3.3 or you will be unable to run your application.
Keep Things In Order
The order of the previous steps didn’t really matter. Unit Test before building the application? Sure. Build your wrapper at the end? Why not. But now we do need to make sure that the application is made prior to running the automation test. I know this seems overly obvious, but I felt that it needed to be said that you had to have a build application to test on. This isn’t so with FlexUnit tests as the application required to run and the code are separate from the main application. Now with the automated tests we need to run against the main compiled application.
Gather the Parts
You can always pull the required parts from my main app, but if you are going to look for them, this is the list that you will need to put together. I would recommend including all this under one folder in your main project so that again the code for your FlexMonkey test isn’t cluttering up the main application.
For most of these files I just went straight to their current source and pulled them from a project titled MonkeyAccessories. This is where you can get the MonkeyTestLauncher (html/swf), AC_OETags, AirMonkeyLibrary (for AIR builds), fluint, monkey-ant-task.jar, and MonkeyFlexUnitLibrary.
The remainder of the files are created either by the FlexMonkey AIR Application or by you. When you create a new FlexMonkey project you can select the location for the project to be hosted. This give you the monkeyTestProject and monkeyTestSuites. Then as you make your tests you will be adding in snapshot files into your snapshots folder. Also, the testSuites folder and it’s contents are created when you select to generate AS3 in the FlexMonkey App. The generated code you “can” edit, but you probably should. More than likely you will never have to go into these folders. Finally there s the test module for your project. This is used if you are running under targeting the specific swf or monkey agent mode (in your project properties).
You can name this module however you like and is used to run the automated test in the MonkeyTestLauncher provided by FlexMonkey.
Here is the code for my module, ANTBuildProjectTestModule.mxml:
<mx:Module implements="net.digitalprimates.fluint.modules.ITestSuiteModule" xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
import testSuites.mainTestSuite.mainTestSuite;
public function getTestSuites():Array
{
var suiteArray:Array = [];
suiteArray.push(new mainTestSuite());
return suiteArray;
}
]]>
</mx:Script>
</mx:Module>
You’ll notice that the module implements an interface provided for you in the MonkeyFlexUnitLibrary and then set the array of testSuites to run from your generated AS3 tests.
With your flexMonkey folder all set up we can now start working with our ANT build file.
The FlexMonkey Steps
To run the FlexMonkey ANT build tasks we will need to add these additional steps after the application has been build.
- Clean and Create the FlexMonkey Report Folder
- Compile the FlexMonkey Tester Module
- Copy Launcher Files into Test Folder
- Run Automated Test
Defining The Monkey Launcher ANT Task
In the earlier steps we were able to use a simple set of jar files to get all the tasks we need added to our build script. Not so with FlexMonkey. Below is the code necessary to run FlexMonkey specific tasks.
<path id="libraries">
<fileset dir="${FlexMonkey.dir}/${FlexMonkeyLibs.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- Define the Monkey launcher ant task -->
<taskdef name="monkey-test-launcher"
classname="com.gorillalogic.flexmonkey.anttask.MonkeyTestLauncherAntTask"
classpathref="libraries" />
And the additional properties added in build.properties…
FlexMonkey.dir=${basedir}/flexMonkey
#flexmonkey jar location
FlexMonkeyLibs.dir=${FlexMonkey.dir}/libs
Now we can access the monkey-test-launcher task later in our build script.
Clean and Create the FlexMonkey Report Folder
Again, we are creating a new folder, only after deleting it to make sure the contents are new…
<echo>Deleting FlexMonkey Report Directory...</echo>
<delete dir="${FlexMonkeyReport.dir}" failOnError="false"
includeEmptyDirs="true" />
<echo>Deleted FlexMonkey Report Directory</echo>
<echo>Creating FlexMonkey Report Directory...</echo>
<mkdir dir="${FlexMonkeyReport.dir}" />
<echo>Created FlexMonkey Report Directory</echo>
</target>
And the additional properties added in build.properties…
FlexMonkeyReport.dir=${basedir}/flexMonkeyReport
Compile the FlexMonkey Tester Module
Just as if we were building the application we need to build the module that includes our generated AS3 code provided to us from the FlexMonkey application.
We output this file to our test folder so that it is cleaned up after the build is complete.
<echo>Compiling FlexMonkey Tester To Test</echo>
<mxmlc file="${FlexMonkeySrc.dir}/${FlexMonkeyModule.name}.mxml"
incremental="false"
actionscript-file-encoding="UTF-8"
output="${FlexMonkeyModule.file}"
debug="${Debug.Boolean}"
keep-generated-actionscript="false">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<compiler.source-path path-element="${FlexMonkeySrc.dir}" />
<compiler.library-path dir="${FlexMonkeyLibs.dir}" append="true">
<include name="*.swc"/>
</compiler.library-path>
</mxmlc>
<echo>Compiled FlexMonkey Tester To Test</echo>
</target>
And the additional properties added in build.properties…
FlexMonkeyModule.name=ANTBuildProjectTestModule
#flexmonkey module
FlexMonkeyModule.file=${Test.dir}/${FlexMonkeyModule.name}.swf
#flexmonkey src location
FlexMonkeySrc.dir=${FlexMonkey.dir}/src
Copy Launcher Files into Test Folder
Now we need to do some moving around of files to get ready for the final build. We wouldn’t want our version of the MonkeyTestLauncher to get corrupted in any way, so we move a copy into the test folder – again, this will be cleaned at the end of the build. While researching this I also found that some users experienced bugs/hangs/strange behavior when the swf file to test was located in a folder different from the compiled module and the MonkeyTestLauncher. So in this step we will also create a copy of this application and move it into our test folder. Now with all the ingredients assembled we are ready to shake & bake.
<echo>Copy Launcher to Test</echo>
<copy todir="${Test.dir}" includeemptydirs="false" overwrite="true">
<fileset dir="${FlexMonkeyLauncher.dir}"/>
</copy>
<echo>Copied Launcher to Test</echo>
<echo>Copy App to Test</echo>
<copy todir="${Test.dir}" overwrite="true" file="${Deploy.dir}/${Application.name}${timestamp}.swf"/>
<echo>Copied App to Test</echo>
</target>
And the additional properties added in build.properties…
FlexMonkeyLauncher.dir=${FlexMonkey.dir}/launcher
Run Automated Test
We have now assembled all of our files into the test folder, which when the build is complete will be wiped and not take any room on our drives.
Now we get to use the monkey-test-launcher task that we defined earlier, all we need to tell it is where to find the launcher application, the target swf (the main app that we are testing), the module that includes our generated AS3 test suite instructions, our snapshot directory with any necessary snapshots required to check against, the toDir (output directory) for the junit reports, and finally a flag to stop the build script if a failure is discovered – haltonfailure.
Once the monkey-test-launcher task is complete we again take the junit formatted reports and build a pretty human readable report by using the junitreport task.
<monkey-test-launcher
timeout="0"
launcher="${FlexMonkeyLauncher.file}"
targetSwf="${Test.dir}/${Application.name}${timestamp}.swf"
testModuleSwf="${FlexMonkeyModule.file}"
snapshotDir="${Snapshots.dir}"
toDir="${FlexMonkeyReport.dir}"
haltonfailure="false"/>
<junitreport todir="${FlexMonkeyReport.dir}">
<fileset dir="${FlexMonkeyReport.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${FlexMonkeyReport.dir}/html"/>
</junitreport>
</target>
And the additional properties added in build.properties…
Snapshots.dir=${FlexMonkey.dir}/snapshots
#flexmonkey launcher app
FlexMonkeyLauncher.file=${Test.dir}/MonkeyTestLauncher.html
Do It!
Go on! Put it all together and try it out. You’ll be tickled pink to watch the build script open and close windows and run your test applications.
Current File
We are now done putting together our entire build script with all the bells and whistles. There is still on more post with all the source code, make sure to check it out in case you don’t like typing or copying & pasting.
Currently your build script should look similar to this:
<project name="Build File" basedir="." default="compileProject">
<!-- Set Up ================================================= -->
<!-- file description -->
<description>Build Script</description>
<!--location of property file -->
<property file="./build.properties"
description="properities for builds" />
<!-- timestamp -->
<tstamp>
<format property="timestamp" pattern="yyyyMMdd" />
</tstamp>
<!-- additional tasks -->
<taskdef resource="flexTasks.tasks" classpath="${FlexTasks.file}"/>
<taskdef resource="flexUnitTasks.tasks" classpath="${FlexUnitTasks.file}"/>
<!-- ======================================================== -->
<!-- Compile Project ======================================== -->
<target name="compileProject"
depends="cleanDeploy,buildWrapper,buildCustomWrapper,copyNonEmbeddedFiles,compileLibraries,runFlexUnitTests,compileApplication,runFlexMonkeyTests,asDocs,cleanTempDirectories"
description="compiles application"/>
<!-- Build Wrappers ========================================= -->
<target name="buildWrapper">
<echo>Building Wrapper...</echo>
<html-wrapper title="${Application.name}"
height="100%" width="100%"
bgcolor="#FFFFFF" file="${Application.name}.html"
application="${Application.name}"
swf="${Application.name}${timestamp}"
version-major="${Major.version}"
version-minor="${Minor.version}"
version-revision="${Revision.version}"
history="true"
template="express-installation"
output="${Deploy.dir}" />
<echo>Built Wrapper</echo>
</target>
<target name="buildCustomWrapper">
<echo>Building Custom Wrapper...</echo>
<copy file="${Template.file}" tofile="${Deploy.dir}/${Output.file}" overwrite="true">
<filterchain>
<replacetokens>
<token key="version_major" value="${Major.version}"/>
<token key="version_minor" value="${Minor.version}"/>
<token key="version_revision" value="${Revision.version}"/>
<token key="application" value="${Application.name}"/>
<token key="width" value="100%"/>
<token key="height" value="100%"/>
<token key="bgcolor" value="#FFFFFF"/>
<token key="swf" value="${Application.name}${timestamp}"/>
</replacetokens>
</filterchain>
</copy>
<echo>Built Custom Wrapper</echo>
</target>
<!-- ======================================================== -->
<!-- Compile Application ==================================== -->
<target name="compileApplication">
<echo>Compiling SWF To Deploy</echo>
<mxmlc file="${Src.dir}/${Application.name}.mxml"
incremental="false"
actionscript-file-encoding="UTF-8"
output="${Deploy.dir}/${Application.name}${timestamp}.swf"
debug="${Debug.Boolean}"
keep-generated-actionscript="false">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<default-background-color>0xFFFFFF</default-background-color>
<metadata>
<creator>Jonathan Campos</creator>
<publisher>UnitedMindset</publisher>
<language>EN</language>
</metadata>
<compiler.source-path path-element="${Src.dir}" />
<compiler.library-path dir="${basedir}/${DeploySWC.dir}" append="true">
<include name="*.swc"/>
</compiler.library-path>
</mxmlc>
<echo>Compiled SWF To Deploy</echo>
</target>
<!-- ======================================================== -->
<!-- NONEMBEDDED FILES ====================================== -->
<target name="copyNonEmbeddedFiles">
<echo>Deleting Deploy Assets Directory...</echo>
<delete dir="${DeployAssets.dir}" failOnError="false" includeEmptyDirs="true" />
<echo>Deleted Deploy Assets Directory</echo>
<echo>Creating Assets Folder</echo>
<mkdir dir="${DeployAssets.dir}"/>
<echo>Created Assets Folder</echo>
<echo>Copy Nonembedded Resources To Deploy</echo>
<copy todir="${DeployAssets.dir}" includeemptydirs="false" overwrite="true">
<fileset dir="${Assets.dir}"/>
</copy>
<echo>Copied Nonembedded Resources To Deploy</echo>
</target>
<!-- ======================================================== -->
<!-- COMPILE LIBRARIES ====================================== -->
<target name="compileLibraries" depends="cleanDeploySWCs,copyPrecompiledSWCs,compileLibrary" />
<target name="cleanDeploySWCs">
<echo>Deleting Deploy SWC Directory...</echo>
<delete dir="${DeploySWC.dir}" failOnError="false" includeEmptyDirs="true"/>
<echo>Deleted Deploy SWC Directory</echo>
<echo>Creating Deploy SWC Directory...</echo>
<mkdir dir="${DeploySWC.dir}"/>
<echo>Created Deploy SWC Directory</echo>
</target>
<target name="copyPrecompiledSWCs">
<echo>Copying to Deploy SWC Directory...</echo>
<copy todir="${DeploySWC.dir}" includeemptydirs="false" overwrite="true">
<fileset dir="${ApplicationLibs.dir}"/>
</copy>
<echo>Copied to Deploy SWC Directory...</echo>
</target>
<target name="compileLibrary" description="compiles the Library">
<echo>Compiling Library SWC To Deploy SWC Folder</echo>
<compc debug="${Debug.Boolean}" output="${DeploySWC.dir}/${Library.name}.swc">
<source-path path-element="${LibrarySrc.dir}"/>
<include-sources dir="${LibrarySrc.dir}" includes="*"/>
<compiler.library-path dir="${LibraryLibs.dir}" append="true">
<include name="*.swc"/>
</compiler.library-path>
<metadata>
<creator>Jonathan Campos</creator>
<publisher>UnitedMindset</publisher>
<language>EN</language>
</metadata>
</compc>
<echo>Compiled Library SWC To Deploy SWC Folder</echo>
</target>
<!-- Clean Up =============================================== -->
<target name="cleanDeploy" description="Cleans the deploy file">
<echo>Deleting Deploy Directory...</echo>
<delete dir="${Deploy.dir}" failOnError="false"
includeEmptyDirs="true" />
<echo>Deleted Deploy Directory</echo>
<echo>Creating Deploy Directory...</echo>
<mkdir dir="${Deploy.dir}" />
<echo>Created Deploy Directory</echo>
</target>
<target name="cleanTempDirectories">
<echo>Deleting Deploy SWC Directory...</echo>
<delete dir="${DeploySWC.dir}" failOnError="false" includeEmptyDirs="true"/>
<echo>Deleted Deploy SWC Directory</echo>
<echo>Deleting Test Directory...</echo>
<delete dir="${Test.dir}" failOnError="false"
includeEmptyDirs="true" />
<echo>Deleted Test Directory</echo>
</target>
<!-- ======================================================== -->
<!-- ASDOC ================================================== -->
<target name="asDocs" depends="cleanASDoc,compileASDoc" description="build of asdocs" />
<!-- Delete the existing output folder and files and then regenerate the output folder -->
<target name="cleanASDoc">
<echo>Deleting ASDoc Directory...</echo>
<delete dir="${Asdoc.dir}" failOnError="false" includeEmptyDirs="true" />
<echo>Deleted ASDoc Directory</echo>
<echo>Creating ASDoc Directory...</echo>
<mkdir dir="${Asdoc.dir}" />
<echo>Created ASDoc Directory</echo>
</target>
<!-- Run the ASDoc executable and generate the ASDocs to the new output folder -->
<target name="compileASDoc">
<echo>ASDoc Compiling...</echo>
<exec executable="${AsDocs.executable}" failonerror="true">
<arg line="-doc-sources '${AppClasses.dir}'" />
<arg line="-doc-sources '${LibrarySrc.dir}'" />
<arg line="-external-library-path '${LibrarySrc.dir}'" />
<arg line="-external-library-path '${Library.dir}/${LibraryLibs.dir}'" />
<arg line="-main-title '${Main.title}'" />
<arg line="-window-title '${Window.title}'" />
<arg line="-output '${Asdoc.dir}'" />
<arg line="-footer '${Footer.text}'" />
</exec>
<echo>ASDoc Compile Complete</echo>
</target>
<!-- ======================================================== -->
<!-- FlexUnit =============================================== -->
<target name="runFlexUnitTests"
description="run flexunit tests"
depends="cleanFlexUnitReport,cleanTest,compileTestRunner,executeTestRunner"/>
<target name="cleanFlexUnitReport" description="Cleans the Report file">
<echo>Deleting FlexUnit Report Directory...</echo>
<delete dir="${FlexUnitReport.dir}" failOnError="false"
includeEmptyDirs="true" />
<echo>Deleted FlexUnit Report Directory</echo>
<echo>Creating FlexUnit Report Directory...</echo>
<mkdir dir="${FlexUnitReport.dir}" />
<echo>Created FlexUnit Report Directory</echo>
</target>
<target name="cleanTest" description="Cleans the Test file">
<echo>Deleting Test Directory...</echo>
<delete dir="${Test.dir}" failOnError="false"
includeEmptyDirs="true" />
<echo>Deleted Test Directory</echo>
<echo>Creating Test Directory...</echo>
<mkdir dir="${Test.dir}" />
<echo>Created Test Directory</echo>
</target>
<target name="compileTestRunner">
<echo>Compiling Test Runner SWF To Test</echo>
<mxmlc file="${TestRunnerSrc.dir}/${TestRunner.name}.mxml"
output="${Test.dir}/${TestRunner.name}.swf">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<compiler.source-path path-element="${Src.dir}" />
<compiler.library-path dir="${basedir}/" append="true">
<include name="${DeploySWC.dir}"/>
</compiler.library-path>
<compiler.library-path dir="${TestRunnerLib.dir}" append="true">
<include name="*.swc"/>
</compiler.library-path>
<compiler.verbose-stacktraces>true</compiler.verbose-stacktraces>
<compiler.headless-server>true</compiler.headless-server>
</mxmlc>
<echo>Compiled Test Runner SWF To Test</echo>
</target>
<target name="executeTestRunner" description="executes the test runner app">
<echo>Running Test Runner SWF</echo>
<flexunit swf="${Test.dir}/${TestRunner.name}.swf"
toDir="${FlexUnitReport.dir}"
haltonfailure="false"
verbose="true"
localTrusted="true"/>
<echo>Ran Test Runner SWF</echo>
<echo>Generate Readable Tests</echo>
<junitreport todir="${FlexUnitReport.dir}">
<fileset dir="${FlexUnitReport.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${FlexUnitReport.dir}/html"/>
</junitreport>
<echo>Generated Readable Tests</echo>
</target>
<!-- ======================================================== -->
<!-- FlexMonkey ============================================= -->
<target name="runFlexMonkeyTests"
description="run flexmonkey tests"
depends="cleanFlexMonkeyReport,
compileFlexMonkeyTester,
copyLauncherToTestFolder,runAutomatedTest"/>
<!-- Location of the Monkey ant tasks -->
<path id="libraries">
<fileset dir="${FlexMonkey.dir}/${FlexMonkeyLibs.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
<!-- Define the Monkey launcher ant task -->
<taskdef name="monkey-test-launcher"
classname="com.gorillalogic.flexmonkey.anttask.MonkeyTestLauncherAntTask"
classpathref="libraries" />
<target name="cleanFlexMonkeyReport" description="Cleans the Report file">
<echo>Deleting FlexMonkey Report Directory...</echo>
<delete dir="${FlexMonkeyReport.dir}" failOnError="false"
includeEmptyDirs="true" />
<echo>Deleted FlexMonkey Report Directory</echo>
<echo>Creating FlexMonkey Report Directory...</echo>
<mkdir dir="${FlexMonkeyReport.dir}" />
<echo>Created FlexMonkey Report Directory</echo>
</target>
<target name="compileFlexMonkeyTester">
<echo>Compiling FlexMonkey Tester To Test</echo>
<mxmlc file="${FlexMonkeySrc.dir}/${FlexMonkeyModule.name}.mxml"
incremental="false"
actionscript-file-encoding="UTF-8"
output="${FlexMonkeyModule.file}"
debug="${Debug.Boolean}"
keep-generated-actionscript="false">
<load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
<compiler.source-path path-element="${FlexMonkeySrc.dir}" />
<compiler.library-path dir="${FlexMonkeyLibs.dir}" append="true">
<include name="*.swc"/>
</compiler.library-path>
</mxmlc>
<echo>Compiled FlexMonkey Tester To Test</echo>
</target>
<target name="copyLauncherToTestFolder">
<echo>Copy Launcher to Test</echo>
<copy todir="${Test.dir}" includeemptydirs="false" overwrite="true">
<fileset dir="${FlexMonkeyLauncher.dir}"/>
</copy>
<echo>Copied Launcher to Test</echo>
<echo>Copy App to Test</echo>
<copy todir="${Test.dir}" overwrite="true" file="${Deploy.dir}/${Application.name}${timestamp}.swf"/>
<echo>Copied App to Test</echo>
</target>
<target name="runAutomatedTest">
<monkey-test-launcher
timeout="0"
launcher="${FlexMonkeyLauncher.file}"
targetSwf="${Test.dir}/${Application.name}${timestamp}.swf"
testModuleSwf="${FlexMonkeyModule.file}"
snapshotDir="${Snapshots.dir}"
toDir="${FlexMonkeyReport.dir}"
haltonfailure="false"/>
<junitreport todir="${FlexMonkeyReport.dir}">
<fileset dir="${FlexMonkeyReport.dir}">
<include name="TEST-*.xml"/>
</fileset>
<report format="frames" todir="${FlexMonkeyReport.dir}/html"/>
</junitreport>
</target>
<!-- ======================================================== -->
</project>
And your properties:
#
# Compiler Properties
#
#####################################################################
# Flex SDK File Location
FLEX_HOME=C:/Program Files/Adobe/Flex Builder 3 Plug-in/sdks/3.3
#flextasks jar location
FlexTasks.file=flexTasks/flexTasks.jar
#deploy directory
Deploy.dir=deploy
#source directory
Src.dir=src
#debug flag
Debug.Boolean=false
#application name
Application.name=ANTBuildProject
#version major
Major.version=9
#version minor
Minor.version=0
#version revision
Revision.version=124
#Template File
Template.file=index.template.html
#Output HTML File
Output.file=index.html
#Assets
Assets.dir=${Src.dir}/assets
#Assets
DeployAssets.dir=${Deploy.dir}/assets
#Deploy SWC Directory
DeploySWC.dir=deploySWC
#Library Directory
Library.dir=C:/workspace/ANTBuildLibrary
#Library Libs
LibraryLibs.dir=${Library.dir}/libs
#Library Src
LibrarySrc.dir=${Library.dir}/src
#library name
Library.name=ANTBuildLibrary
#Application Libs
ApplicationLibs.dir=${basedir}/libs
#####################################################################
#
# ASDoc Properties
#
#####################################################################
#asdoc output
Asdoc.dir=asdoc
#the location of asdocs on your computer
AsDocs.executable=${FLEX_HOME}/bin/asdoc.exe
#Asdoc Footer Text
Footer.text=Some legal jargon
#window title
Window.title=Window Title
#main title
Main.title=Main Title
#the location of your application classes on your computer
AppClasses.dir=${basedir}/src
#####################################################################
#
# FlexUnit Properties
#
#####################################################################
#report output file
FlexUnitReport.dir=${basedir}/flexUnitReport
#test dir
Test.dir=${basedir}/test
#flextasks jar location
FlexUnitTasks.file=flexTasks/flexUnitTasks-4.0.0.jar
#Test Runner Dir
TestRunner.dir=C:/workspace/AntBuildUnitTest
TestRunnerSrc.dir=${TestRunner.dir}/src
TestRunnerLib.dir=${TestRunner.dir}/libs
#Test Runner Dir
TestRunner.name=ANTBuildUnitTest
#####################################################################
#
# FlexMonkey Properties
#
#####################################################################
#flexmonkey jar location
FlexMonkey.dir=${basedir}/flexMonkey
#flexmonkey jar location
FlexMonkeyLibs.dir=${FlexMonkey.dir}/libs
#flexmonkey src location
FlexMonkeySrc.dir=${FlexMonkey.dir}/src
#report output file
FlexMonkeyReport.dir=${basedir}/flexMonkeyReport
#flexmonkey launch
FlexMonkeyLauncher.dir=${FlexMonkey.dir}/launcher
#flexmonkey launcher app
FlexMonkeyLauncher.file=${Test.dir}/MonkeyTestLauncher.html
#flexmonkey module
FlexMonkeyModule.name=ANTBuildProjectTestModule
#flexmonkey module
FlexMonkeyModule.file=${Test.dir}/${FlexMonkeyModule.name}.swf
#snapshots
Snapshots.dir=${FlexMonkey.dir}/snapshots





excellent article, thanks for sharing!
My Flex app uses RESTFul web services. To support all methods I am using javascript in the wrapper HTML to interact with the services. My assumption is that tartgetting my app SWF will stop interaction with javascript. Can I target the wrapper HTML in the continuous integration testing environment as mentioned on this post?
Yes, you definitely can run your app in the “Monkey Link” mode. This way you will use the original wrapper and connect via LocalConnection.
Where i can set the settings related “Monkey Link” mode i.e. i need more information against the comments posted by Gurpreet on May 3rd, 2010 at 4:09 am
Please have a look on the wrapper section of the build file:
Building Wrapper…
Built Wrapper
Building Custom Wrapper…
Built Custom Wrapper
target name=”buildWrapper”>
echo>Building Wrapper…
html-wrapper
title=”RMSultra”
file=”index.html”
height=”300″
width=”400″
bgcolor=”red”
application=”RMSultra”
swf=”E:/Apache-ANT/RMS_ultra/bin-debug/Test/RMSultra”
version-major=”9″
version-minor=”0″
version-revision=”0″
history=”false”
template=”express-installation”
output=”E:/Apache-ANT/RMS_ultra/bin-debug/DeploySWC” />
echo>Built Wrapper
target>
target name=”buildCustomWrapper”>
echo>Building Custom Wrapper…
copy file=”E:/Apache-ANT/RMS_ultra/RMSultra/launcher/index.template.html” tofile=”E:/Apache-ANT/RMS_ultra/bin-debug/DeploySWC/index.html” overwrite=”true”>
filterchain>
replacetokens>
token key=”version_major” value=”9″/>
token key=”version_minor” value=”0″/>
token key=”version_revision” value=”0″/>
token key=”application” value=”RMSultra”/>
token key=”width” value=”100%”/>
token key=”height” value=”100%”/>
token key=”bgcolor” value=”#FFFFFF”/>
token key=”swf” value=”E:/Apache-ANT/RMS_ultra/bin-debug/test/”/>
replacetokens>
filterchain>
copy>
Built Custom Wrapper
When you are using the FlexMonkey application to set up your testing, just select in the properties “MonkeyLink”. To get this to work you will need to compile the application with the automation swcs and the flexmonkey automation swcs. Then the MonkeyLink can be established.
After that, to automate it you just need to build a module that runs your automated tests and can run from the flexmonkey jar. Then you can tie it into ant just the way you did before.
I know this seems like a lot of steps but you can easily take care of this in just a few hours.
At some point I should stop and write out instructions as to how to do all of this.
Thanks for your inputs…
hi all,
as per jonathan’s words, i have used the monkeylink option , compiled my application with the required swcs and also the connection is established. Now, while automating, my module complies fine and when i run my app from ANT i see the following
D:\>ant -buildfile d:/projects/antproject/build.xml run_functional_test
Buildfile: d:\projects\antproject\build.xml
init:
[delete] Deleting directory d:\projects\antproject\bin-debug
[mkdir] Created dir: d:\projects\antproject\bin-debug
compile_test_module:
[java] Loading configuration file D:\Program Files\Adobe\Flex Builder 3\sdk
s\3.5\frameworks\air-config.xml
[java] D:\projects\antproject\bin-debug\monkeyTester.swf (1383886 bytes)
compile_functional_test:
[java] Loading configuration file D:\Program Files\Adobe\Flex Builder 3\sdk
s\3.5\frameworks\air-config.xml
[java] D:\projects\antproject\bin-debug\antproject.swf (1947791 bytes)
[copy] Copying 1 file to d:\projects\antproject\bin-debug
run_functional_test:
[monkey-test-launcher] Invoking runner with command: rundll32 url.dll,FileProtoc
olHandler d:\Program Files\Adobe\Flex Builder 3\sdks\3.5\bin\adl.exe .\bin-debug
\antproject-app.xml
[monkey-test-launcher] Opened server socket
and nothing happens after this. I am eager to know what it means and additional information about the launcher and tester would be appreciated
When you compiled your application, did you make sure to compile in the monkey link swcs? This is what allows the two to talk. I’ll work up a monkeylink specific blog post shortly, sadly they do take some time
thanks for your reply,
but i did not make out whats compiling in the monkey link swcs. While establishing connection with the flex monkey i added the following swcs in the project libs folder , AirMonkeyLibrary.swc, automation_monkey.swc, Easy2BuildMonkeyLink.swc, FlexAutomationLibrary.swc, fluint.swc, MonkeyFlexUnitLibrary.swc.. with these been included along with monkey-ant-task.jar in my library i could establish the connection to flex monkey. I also generated the tests and the module required to automate testing is also ready.
Am i missing anything till here? Please let me know jonanthan
No, those are the correct swcs. Let me play with it and see if I can come up with a better explaination.
thanks for your reply,
Just to make it easy for you to debug the error, i want to tell few things about my project. I am building an AIR application which has very simple button controls and label and nothing complicated. Is it necessary that we have to have monkeyTest launcher ( i.e MonkeyTestLauncher (html/swf), AC_OETags, ) as i am not using any HTML component. is this what is the reason for the opened srever socket problem? This info might help for you to understand my problem better.
Nope, none of that is necessary to run the monkey link. The socket server is made so that the external app can talk to your application. If you are trying for immediate resolution I’d say to hit up the FlexMonkey support system. Anything I do will still be a ways out between the day job and side work.
Hi,
I met an issue while using ant run our application.
At beginning it runs ok, when tests go to next swf (click step redirect page to next swf ), the ant script quit, and junit report has 0 test results.(actually 2 cases has been run.) Do you meet same issue? the case is we launch main.jsp, it has first swf included, when test go and call next swf, the issue happens, thanks for advice.
@KC I have actually have seen that issue for the same exact reason. We needed to move pages for our app. So what I did was setup a testing project per swf so that I could test each individually. Does that make sense? I know it takes extra effort, but it’s what must be done.