Flash/Flex Testing

The Flash/Flex Test Automation Plugin (for Windows Internet Explorer and Firefox) provides a smooth integration with the Ranorex Automation Framework and its tools. You can easily filter, access and validate Flex controls easily using RanoreXPath. You have full access to all the properties and attributes of Flash and Flex elements.

Prerequisites

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

Samples

A flash/flex test sample project is included with the Ranorex installation package (shown on the startpage of Ranorex Studio).

Methods for loading the Automation Lib

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

Loader

The RanorexLoader enables automation of your flash/flex application without including the automation lib directly into your application.

  • No modifications to your swf needed
  • Loads your application in a container (could cause limitations)
  • If you have a bunch of swf files, you will have to adopt the url for each of them
  • Loader swf has to be copied to the web server

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 (Supported = supported, Recommended = recommended):

Flash

Flex

AIR*

CS3 CS4 3.X 4.X 2.X
Loader
RanorexLoader.swf Supported Supported Supported
RanorexLoaderFlex4.swf Supported
Automation Lib

Ranorex.swc

Supported Supported
RanorexFlex4.swc Supported
RanorexAIR2.swc Supported
RanorexAIR2Flex35.swc Supported
Module
RanorexModule.swf Supported Supported Supported
RanorexModuleFlex4.swf Supported
* Support for Adobe AIR 2 Release in combination with Flex 3.5 and Flex 4 Release

Test Automation of Flash/Flex controls with Ranorex

The architecture of a Flash/Flex object is easy to see within Ranorex Spy. All embedded Flash or Flex elements are shown as a Flex element in the tree view.

Use Ranorex Recorder to automate Flash/Flex applications in Internet Explorer and Firefox. You can add user code actions to your recordings to access custom Flex properties.

Test Automation of Flash/Flex Applications

How to read/set attributes and styles

You can read/set common attributes (e.g. the checkstate of a checkbox) directly by using the adaptor as follows:
// Set the checked state with the property "Checked"
repo.FlexTestPageDom.CheckBox_Control_Example.CheckBoxEggs.Checked = true;
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<FlexElement>();
sliderFlex["value"] = "100";

FlexElement containerFlex = repo.FlexTestPageDom.Self.FindSingle(".//container[@caption='Tree Control']");
containerFlex.SetStyle("borderColor","#ee0000");

Using the Ranorex Loader

The RanorexLoader enables automation of your flash/flex application without including the automation lib directly into your application.

  1. Copy the RanorexLoader.swf file (or the RanorexLoaderFlex4.swf if you use Flex4) to your web server (where your .swf file is located). You can find the loader in the Bin directory of your Ranorex installation.
  2. Open Internet Explorer or Firefox with following url and set the “rxtarget” parameter to your flash file as follows:
    "http://www.yourserver.com/RanorexLoader.swf?rxtarget=yourflash.swf"
    or
    "file:///C:/.../RanorexLoader.swf?rxtarget=yourflash.swf"
    or
    "http://www.yourserver.com/RanorexLoader.swf?rxtarget=folder/subfolder/yourflash.swf"
  3. 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

  1. Start Adobe Flex Builder and open your workspace
  2. Right-click on your project and choose Properties
  3. Under Flex Compiler add the Ranorex.swc (RanorexFlex4.swf for Flex4, RanorexAIR2.swc for AIR2 with Flex4, RanorexAIR2Flex35.swc for AIR2 with Flex3.5) file (located in the Bin directory of your Ranorex installation) to the the compiler argument as follows:
    -include-libraries "C:\Program Files\Ranorex 2.X\Bin\Ranorex.swc"
  4. For AIR2: Append following code to your "applicationCompleteHandler" function:
    import Ranorex.RxAutomation;   
    RxAutomation.Init();  
  5. Save and compile your application
  6. Run your application in Internet Explorer or Firefox
  7. 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

  1. Start Adobe Flash CS4 and open your application
  2. Open the "Publish Settings" dialog (File->Publish Settings)
  3. Include the Ranorex Flash Library in your Flash application under Flash->Script->Settings...->Library Path and choose "Browse to SWC file"
  4. Select "Ranorex.swc" file in the browse dialog (Ranorex.swc is located in the Bin directory of your Ranorex installation)
  5. Insert following code to your ACTIONS:
    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);
    	}
    }
  6. Run your application in Internet Explorer or Firefox
  7. 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

  1. Start Adobe Flash CS3/CS4 and open your application
  2. Insert following code to your ACTIONS (by pressing F9):
  3. 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("RanorexModule.swf"));
  4. Copy the RanorexModule.swf file, located in the Bin directory of your Ranorex installation, to your web server (where your .swf file is located)
  5. Run your application in Internet Explorer or Firefox
  6. 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 www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html
    2. Add your project output directory

How to load the Ranorex Module into your Flex application

  1. Start Adobe Flex Builder or Flash Builder and open your workspace
  2. Append following code to your "applicationCompleteHandler" function or initialization code:
    For Flex 3:
  3. var rxloader : Loader = new Loader();
    Application.application.rawChildren.addChild(rxloader);
    rxloader.name = "__rxloader";
    rxloader.width = 0; rxloader.height = 0;
    rxloader.load(new URLRequest("RanorexModule.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("RanorexModuleFlex4.swf"));
  4. Copy the RanorexModule.swf file (or the RanorexModuleFlex4.swf if you use Flex4), located in the Bin directory of your Ranorex installation, to your web server (where your .swf file is located)
  5. Run your application in Internet Explorer or Firefox
  6. 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 www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04a.html
    2. Add your project output directory