Skip to content

Flash Testing Setup

admc edited this page Sep 14, 2010 · 5 revisions

Flash Debugger Version (optional)

To do anything with Flash, you’ll want to get the Debugger Version of the Flash player. Download it from Adobe’s Flash Player download page

Once you have the debug player, you’ll need to configure it to log errors. Adobe has detailed documentation for setting it up.

Building FlexPilot Flash (optional)

You can build FlexPilot Flash by running the build.py script in the /flash directory. Run `./build.py -help` to see the list of available build targets. `./build.py -t flex_pilot` builds FlexPilot Flash (FlexPilot.swf).

  • Important: If you would rather not deal with building it, you can simply download and use the pre-built
    FlexPilot.swf.

Importing FPBootstrap

There is no need to compile all the FlexPilot code into your app, or link to a SWC file at compile time. Just include the small `FPBootstrap` package, like so:

import org.flex_pilot.FPBootstrap;

To help your compiler find it, you may need to use the `-source-path` option to append a directory in which the compiler will look for libraries. Use the “plus-equals” syntax to append, not replace, like so:

mxmlc -source-path=. -source-path+=../lib ByTorApp.mxml -o ByTorApp.swf

In the above example, /org/flex_pilot is in the lib directory one level above where I’m compiling.

`FPBootstrap` is a tiny module that contains only enough code to load the FlexPilot Flash SWC via a Loader class into your application’s `ApplicationDomain`. This approach allows you to run tests against your apps without recompiling. You can even do automated testing of production apps.

Initializing FPBootstrap

To load FlexPilot Flash and begin using it in your app, you’ll need to set `FPBootstrap.flex_pilotLibPath`, the path on the server where `FPBootstrap` can find FlexPilot.swf. The Loader fetches FlexPilot.swf via a Loader class, so this path must be a path on your server, not a local file path.

Next, you have to initialize it. This tells `FPBootstrap` to fetch and load FlexPilot.swf, and gives FlexPilot Flash a context to use for testing. This context is usually a reference to your app’s Stage.

These two steps are done like this:

FPBootstrap.flex_pilotLibPath = '/flash/org/flex_pilot/FlexPilot.swf';
FPBootstrap.init(stage);

The init process can be run based on passed flashVars, or by conditional compilation.

MXML Applications

To load FlexPilot Flash into a MXML application you must modify your mx:Application tag to initialize the FPBootstrapper when the stage is loaded and ready:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="init();">

An example for your mxml file:

<mx:Script>
<![CDATA[
  import org.flex_pilot.FPBootstrap;
  private function init():void {
    FPBootstrap.flex_pilotLibPath = 'FlexPilot.swf';
    FPBootstrap.init(stage);
  }
]]></mx:Script>

The above assumes that you have built and put the FlexPilot.swf in the same web root that the application is going to be served from, however as outlined above if you would like to put it in a different web accessible location you can do so, just update the flex_pilotLibPath to reflect that.

Does it work?

The best way to test if it works is by using Firebug to get a handle on your movie and check of the FlexPilot Testing API’s have been exposed.

If your flash movie has a DOM id of ‘testApp’:
document.getElementById('testApp').fp_click

If Firebug says ‘function’, then everything is working and ready to go and you can now move on to using the FlexPilot IDE to record and play back tests.

What now?

You can run your tests in a functional way from JavaScript (FlexPilot etc): API
Or
Write your tests all in AS3, build them and run them inside the app (fast, great for unit tests): ActionScript Tests