Setting up your environment for Flash/Flex Automation

Before going into details about some of the tools mentioned in the previous post, we thought it would be a good idea to start with what you need to do to get your environment ready for Flex/Flash automation. There’s a lot of information out there but there isn’t a place that walks you through the entire process – so we decided to write everything down and try to make it easier for other users.
Here is what you need to get started:
1. A Web Server
You will need to install and configure a web server or make sure you have access to one where you can upload your .html and .swf files. This is the server that you will direct your test scripts to as well.
We won’t go into details here – the most obvious choice, if you don’t already have access to one, is to install Apache.
However, if you prefer to run all your tests locally, you will need to change your Flash Player settings to allow local Flash content to connect to the internet. Here’s how you do that:
This link will bring up your Flash Player Settings Manager.. Go to the “Global Security Settings”, go to “Edit Locations” and add the local .swf file that you want to test.
2. Flash Builder or another IDE of your choice

There are several ways (depending on the tools you plan to use as well) to setup your automation environment. All of them, though, require compilation of a Flex project, so you will need an environment that allows you to do that. At first, you can download the Flash Builder and use the 60 day trial. Note that if you plan to use Adobe’s Automation Framework you will only be allowed to use 30 actions/test script, unless you have a FlexBuilder Pro Licence. The Framework for Flex 2 used to be available within the LiveCycle Data Services package,for which, as far as we know, you can get a free Licence by registering on the site if you only need it for development purposes. But since Flex 3, the Framework is no longer provided in LCDS.

Depending on the preferred approach and the chosen automation tools, there are several ways to start your flex/flash automation.
Let’s say you want to test a Test.swf application.
Option 1 – Using Adobe’s Automation Framework and an Automation tool of your choice
To automatically test your Test.swf application, you need to either have the source code for it and recompile it (probably the best approach) or load your automation libraries at run time.
Here are the instructions for both cases:

Option 1a – Recompiling Test.swf with automation support
Once you have the source code for your Test.swf, you need to recompile the Flex Project after including your automation libraries by using the include-libraries compiler option (in Flash Builder, you just have to go to Project > Properties > Flex Compiler and add them to the “Additional Compiler arguments” field).
You will have to include:
automation.swc
automation_agent.swc
automation_charts.swc (only if your application uses charts)
automation_dmv.swc (for charts or the AdvancedDataGrid classes)

=\”text-align: justify;\”>and any other libraries required by your test automation tool. For example, if you want to use FunFX, you will also have to add the following libraries:

funfx-0.2.2.swc (the current FunFX automation agent)
automation_rb.swc

Option 1b – Loading your automation libraries at run time
If you don’t have the source code, you will have to load your automation libraries at run time before you can test the .swf file that was compiled without automated testing support.
To do this, you need to create an new Flex project and use the SWFLoader to load your Test.swf and also add all the required libraries:

1. Create a new Flex project (let’s call it Wrapper) and have the following MXML file:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
<mx:SWFLoader source="Test.swf" width="100%" height="100%"
</mx:Application>
2. Include all the libraries mentioned at Option 1a as compiler arguments.
3. Compile the project. The Wrapper.html file will then load your Test.swf application and will also load the automation libraries at run time.
4. Direct all your test scripts to Wrapper.html to access the objects in Test.swf.
Note: In the above option the name of the test application is hard-coded inside the wrapper, but there is also the option to pass the name of the application as a parameter.
For example, we have a FunFXLoader (compiled with all the required automation libraries) that we use anytime we want to test a Flex application using FunFX.
The .mxml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="initVars()">
<mx:Script>
<![CDATA[
private function initVars():void{
FunFX.source=Application.application.parameters.testswf;
}
]]>
</mx:Script>
<mx:SWFLoader id="FunFX" width="100%" height="100%">
</mx:Application>
while here you can see what the index.template.html file contains.
Now, to load your Test.swf, you will have to access the following page:
http://mytestsite/FunFXLoader.html?testswf=”Test.swf”
Of course, this can be used with any .swf file as long as you copy it on your web server (relative paths can be used to specify the file location).

Option 2 – Using an ActionScript “Framework”

If you want to use an already developed ActionScript Framework – I guess if you develop one of your own you know how to use it 🙂 – for example SeleniumFlex.as, you must refer the ActionScript file in your main MXML file, like this:

<mx:Script source="YourFramework.as"/>

Option 3 – Using other Automation methods/tools like Test Complete
Automation tools that don’t use Adobe’s Automated Testing API, like Test Complete, have other methods of exposing Flash Objects.
With TestComplete, for example, to access internal objects of Flex applications, you have to compile your Flex application with the Generate accessible SWF file option enabled and make TestComplete recognize Flash elements as MSAA objects. However, this approach only lets you test Flash elements residing on web pages that are shown in Microsoft Internet Explorer or the Microsoft WebBrowser control.
Don't be shellfish...Tweet about this on TwitterShare on FacebookShare on Google+Pin on PinterestShare on LinkedInEmail this to someoneShare on RedditShare on StumbleUpon
Go back


11 responses to “Setting up your environment for Flash/Flex Automation”

  1. Anonymous says:

    >Note that if you plan to use Adobe’s Automation Framework you will only be allowed to use 30 actions/test script unless you get a LiveCycle Data Services Licence

    This is not exactly true. Automation’s 30 actions restriction is lifted if you have Flex Builder Professional license. The LCDS requirement was in Flex 2 and is now gone.

  2. Ru says:

    Thanks for you comment.

    If you have Flex Builder Pro, the 30 actions restriction is indeed lifted, but the Flex Builder Professional license costs €606.28.

    We mentioned the LiveCycle Data Services Licence since that is the only license requirement mentioned in the API documentation and since it would be a good alternative especially for the ones using Flash Builder Standard or any other IDE.

  3. Anonymous from above says:

    As far as I know having LCDS does not unlock automation in Flex 3 anymore, so the only solution is to have Professional license. I may be wrong though.

  4. Alex says:

    Sorry for replying so late.
    You are not wrong, the Test Automation framework used to be available withing LCDS for Flex 2, but since Flex 3 it seems to only be available inside Flex Builder (as stated in our first post on this subject Here)
    We will update the post to clarify this issue.
    Thank you for the feedback.
    Alex

  5. Anonymous says:

    Is it sufficient to have only one licensed version of flex builder with which we can have the flex app compiled instrumenting the automation framework specific libraries and later the flex app can be tested on any number of test machines having flex addin.

    Also, do we require license for flex QTP addin?

  6. Alex says:

    Thank you for your question,

    Once you compile your application with the automation libraries, it can be run on any number of test machines.

    The QTP add-in comes with the Automation Framework, so you don’t need a separate license, but you need a QTP license to use it – create and run your tests.

    Alex

  7. Anonymous says:

    Hey,
    Thanks a lot for this useful post. Can this work if the SWF is embedded in an aspx page. I mean I do not have the swf file, what I have is just the URL to the Flash game. Is there some way in which i can pass the Flash object to the libraries through this URL?

  8. Alex says:

    Hi There,

    I hope this reply doesn’t come too late.
    The answer to this question depends a lot on how the application is built – eg. if the flex application uses any aspx code to communicate with the server of not.
    If it doesn’t, you can download the flash game (in Firefox go to Tools > Page Info > Media tab > select the file and click Save As…) and then use a run time loader (that was compiled with the test automation libraries) to load the application.
    The case described above is not so common, as most of the time there’s communication between the web page and the flash application. In this case I don’t see any way to run some scripts on the flash application if you don’t have its source code… One think that comes into my mind, is that you can try to use a http tracker to download the whole website and modify the code in a way that helps you – I never tried this, so I don’t know if it works or not.

    Thanks,
    Alex

  9. Jay says:

    Hey Alex,
    Thanks for your reply. My case is a bit more complicated than the ones described above. Yes, the Flash app communicates to the server. Also when the Flash app is run and I try to get the swf file, I see multiple pieces of the swf file in the browser temp files (multiple swf files) which may be combining in realtime during play in the RAM. I am not sure though.
    Now my question is, according to the OPTION B described above where we are passing the swf name as a parameter in the query string to the wrapper html, can we pass the flash object instead of the swf filename? since there are chances that i may get the reference to the flash object from the html dom document using elementbyid through vb ?

    Regards,
    Jay

  10. Hi,

    I created a post here in my blog about this type of tools:
    http://www.testalways.com/?p=63

    Thanks,

    Sebi

  11. Web Design says:

    Un articol foarte interesant. De asemenea si blogul este frumos si am gasit o groaza de lucruri interesante. Merita sa-l adaug in bookmark. Tine-o tot asa si te voi vizita in fiecare zi. 🙂