Docs Code Examples
Getting Started with Flash and Flex Testing
Getting Ready
Download the two following files, and put them in the directory with the SWF you would like to test:
Integrating the Loader
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.
Flash Movies
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 = 'FlexPilot.swf';
FPBootstrap.init(stage);
The init process can be run based on passed flashVars, or by conditional compilation.
Flex/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 APIs 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?
Run in any browser with Sauce OnDemand
If you want to run your tests in Selenium RC or Sauce OnDemand, all you need to do is to get the extended version of the RC client from FlexPilot-x's repo and start writing your tests (or export existing ones from Selenium IDE).
To run your new Flex/Flash tests in OnDemand, use the extension URLs flag in our JSON config file and use this as you extension URL:
http://saucelabs.com/ext/flex.js