Flash/Flex testing | Ranorex
Help CenterUser GuideInterfaces and connectivity

Flash/Flex/Air

The Flash/Flex/Air plugin in Ranorex Studio allows it to interface with the controls in such applications. This means you can record Flash/Flex/Air UI elements and work with them in Ranorex Spy.

However, these technologies require some manual instrumentation. Flash and Flex can be instrumented with the Ranorex Instrumentation Wizard in most use cases. Air needs to be instrumented entirely by hand.

This page explains the various instrumentation methods for all the technologies.

In this chapter

    Prerequisites

    The automation of Flash/Flex applications requires inclusion of the Ranorex Flex Automation Lib.

    Methods for loading the Automation Lib

    Depending on your flash/flex application, you can choose to use one of the following flexible instrumentation methods:

    ⇢ PreLoader (recommended)

    The Ranorex PreLoader enables automation of your flash/flex application without modifying the application itself.

    ⇢ Automation Lib

    The AutomationLib swc file has to be included into your flash/flex application (by adding a compiler argument).

    • AutomationLib will be loaded in background (will not affect the functionality of your flash/flex application)
    • No modifications to your website needed

    ⇢ Module

    The Module swf file has to be loaded by adding a code snippet to your ⇢ ACTIONS (for flash) or to your ⇢ ‘applicationCompleteHandler’ function (for flex).

    • Module will be loaded in background (will not affect the functionality of your flash/flex application)
    • No modifications to your website needed
    • Module swf has to be copied to the web server

    The following table shows you the different instrumentation options available for the supported versions of flash/flex:

    Flash Flex AIR*
     CS3 CS4 CS5 3.x 4.x 2.x 3.x 4.x
    Preloader
    Automation Lib
    Module      

    * Support for Adobe AIR2 release in combination with Flex 3.5 and Flex 4 release

      = supported /   = recommended

    How to read/set attributes and styles

    You can read/set common attributes (e.g. the checkstate of a checkbox) directly by using the adapter as follows:

    // Load the slider as a Flex element to access flex attributes FlexElement sliderFlex = repo.FlexTestPageDom.ContainerHSlider_Control.SliderHSlider.As(); sliderFlex["value"] = "100"; FlexElement containerFlex = repo.FlexTestPageDom.Self.FindSingle(".//container[@caption='Tree Control']"); containerFlex.SetStyle("borderColor","#ee0000");
    To access custom attributes and styles, you first have to load your Flex item as a FlexElement in order to read your attributes. Here’s an example:
    // Load the slider as a Flex element to access flex attributes FlexElement sliderFlex = repo.FlexTestPageDom.ContainerHSlider_Control.SliderHSlider.As(); sliderFlex["value"] = "100"; FlexElement containerFlex = repo.FlexTestPageDom.Self.FindSingle(".//container[@caption='Tree Control']"); containerFlex.SetStyle("borderColor","#ee0000");

    Using the Ranorex PreLoader

    The Instrumentation Wizard automatically activates Flash/Flex automation for your machine as ⇢ described here.

    If the automatic instrumentation did not work, you can follow these steps to achieve what the Instrumentation Wizard would have done:
    Install the Adobe Debug Flash Player on the machine on which you would like to record and execute Ranorex test scripts and for all browsers you would like to test with. The respective installers are available on Adobe’s download page.

    Open your user profile directory %UserProfile%, e.g. by opening Windows Explorer and copying the string %UserProfile% into the address bar. Create a new file called ‘mm.cfg’ in your user profile directory and insert the following line of code:

    C:\Program Files\Ranorex X.X\Bin\RanorexAutomation.swf

    where ‘C:\Program Files\Ranorex X.X\Bin\RanorexAutomation.swf’ needs to be replaced by the preloader location of your Ranorex installation. If the ‘mm.cfg’ file already exists, check if the location is correctly set to your current preloader location (Ranorex X.X might change after upgrading to a new version!). In addition to this configuration entry you can enable the logging mechanisms of the Adobe Debug Flash Player, which might be helpful if you have any problems with this kind of instrumentation. In such a case you can then simply provide the logging information to our support team. To enable logging you have to add (or modify) the following line of code to your ‘mm.cfg’ file:

    TraceOutputFileEnable=1

    This additional configuration entry forces the Debug Player to create a log file at following location:

    C:\Users\[username]\AppData\Roaming\Macromedia Flash Player\Logs

    where [username] needs to be replaced by the username that is logged on.

    If you run your application from the local drive, add your output directory to the trusted locations of Flash Player as follows:

    1. Open following link http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065
    2. Add your project output directory

    Adobe Flex: Load the Ranorex Lib into your Flex application

    Start Adobe Flash Builder and open your workspace

    Right-click on your project and choose Properties

    Under Flex Compiler add the RanorexAutomation.swc file (located in the Bin directory of your Ranorex installation) to the the compiler argument as follows:

    -include-libraries "C:/Program Files/Ranorex X.X/Bin/RanorexAutomation.swc"

    Append following code to your ‘applicationCompleteHandler’ function: 

    import Ranorex.RxAutomation; RxAutomation.Init();

    Save and compile your application

    Run your application in a supported browser (Internet Explorer, Firefox, Chrome, Safari)

    If you run your Flex application from the local drive, add your output directory to the trusted locations of Flash Player as follows:

    1. Open following link
      http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065
    2. Add your project output directory

    Adobe Flash: Load the Ranorex Lib into your Flash application

    Start Adobe Flash CS4/CS5 and open your application

    Open the ‘Publish Settings’ dialog (File->Publish Settings)

    Include the Ranorex Flash Library in your Flash application under Flash->Script->Settings…->Library Path and choose ‘Browse to SWC file’

    Select ‘RanorexAutomation.swc’ file in the browse dialog (RanorexAutomation.swc is located in the Bin directory of your Ranorex installation)
    Insert following code to your ACTIONS (by pressing F9):

    import Ranorex.RxAutomation; RxAutomation.InitFromApp(stage);
    OR add the code to your ActionScript source file as follows:
    import mx.controls.*; import flash.events.*; import flash.display.*; import flash.ui.Keyboard; import flash.geom.Rectangle; import fl.events.SliderEvent; // Add Ranorex library import Ranorex.RxAutomation; public class Simple extends MovieClip { public function Simple() { // Add to your constructor RxAutomation.InitFromApp(stage); } }

    Run your application in a supported browser (Internet Explorer, Firefox, Chrome, Safari)

    If you run your Flash application from the local drive, add your output directory to the trusted locations of Flash Player as follows:

    1. Open following link http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065
    2. Add your project output directory

    How to load the Ranorex Module into your Flash application

    Start Adobe Flash CS3/CS4/CS5 and open your application

    Insert following code to your ACTIONS (by pressing F9):

    import flash.net.URLRequest; var rxloader : Loader = new Loader(); stage.addChild(rxloader); rxloader.name = "__rxloader"; rxloader.width = 0; rxloader.height = 0; rxloader.load(new URLRequest("RanorexAutomation.swf"));

    Copy the RanorexAutomation.swf file, located in the Bin directory of your Ranorex installation, to your web server (where your .swf file is located)

    Run your application in a supported browser (Internet Explorer, Firefox, Chrome, Safari)

    If you run your Flash application from the local drive, add your output directory to the trusted locations of Flash Player as follows:

    1. Open following link http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065
    2. Add your project output directory

    How to load the Ranorex Module into your Flex/AIR application

    Start Adobe Flash Builder and open your workspace

    Append following code to your ‘applicationCompleteHandler’ function or initialization code:

    For Flex 3:
    var rxloader : Loader = new Loader(); Application.application.rawChildren.addChild(rxloader); rxloader.name = "__rxloader"; rxloader.width = 0; rxloader.height = 0; rxloader.load(new URLRequest("RanorexAutomation.swf"));

    For Flex 4:

    var rxloader : Loader = new Loader(); FlexGlobals.topLevelApplication.parent.addChild(rxloader); rxloader.name = "__rxloader"; rxloader.width = 0; rxloader.height = 0; rxloader.load(new URLRequest("RanorexAutomation.swf"));

    Copy the RanorexAutomation.swf file, located in the Bin directory of your Ranorex installation, to your web server (where your .swf file is located) or where your AIR application is located.

    Run your application in a supported browser (Internet Explorer, Firefox, Chrome, Safari)

    If you run your Flash application from the local drive, add your output directory to the trusted locations of Flash Player as follows:

    1. Open following link http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html#119065
    2. Add your project output directory

    Troubleshooting

    After instrumenting your Flash/Flex/Air application, Ranorex Studio is still not able to recognize the respective UI elements in your application.

    AllowScriptAccess parameter issues

    The AllowScriptAccess parameter in the HTML code that loads a SWF file controls the ability to perform outbound URL access from within the SWF file.

    Solution: Set this parameter inside the PARAM or EMBED tag to ‘always’.

    AUT instrumented twice

    Your Flash/Flex application was instrumented twice using different versions of the Flash components in provided by Ranorex Studio.

    Solution: Revert to an uninstrumented version of your AUT and use only one of the instrumentation approaches described on this page to instrument your AUT.