To automate Adobe Flash, Flex or AIR applications, you must instrument them to allow Ranorex Studio to identify and interact with elements inside the applications.
You can instrument Flash and Flex applications with the Instrumentation Wizard, but need to instrument AIR applications entirely manually.
This article explains the various instrumentation methods for all the technologies.
Prerequisites
Ensure your environment meets these requirements to allow the automation library to function:
- Debug Player: You must install the Adobe Flash Debug Player on the runtime machine if you intend to use the PreLoader method.
- Flash Player Trust: If you run applications from a local drive, you must add the project output directory to the trusted locations in the Flash Player Settings Manager.
Instrumentation methods
Depending on your flash/flex/AIR application, you can choose to use one of the following flexible instrumentation methods:
- PreLoader: Instruments the app automatically via the Instrumentation Wizard without modifying the application itself. This is the recommended approach for most use cases but requires the Adobe Flash Debug Player.
- Automation Lib: Includes the AutomationLib swc file via compiler arguments. This is ideal when you want the library to load seamlessly in the background. No modifications to your website needed.
- Module: Loads the Module SWF file by adding a small code snippet to your ⇢ ACTIONS (for Flash) or to your ‘applicationCompleteHandler’ function (for Flex). The module is loaded in the background and does not affect the functionality of your application. No modifications to your website needed. The module SWF has to be copied to the web server.
Choose the method that best fits your access to the application source code and the specific technology version you are using.
| 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 |
PreLoader
The Instrumentation Wizard automatically activates Flash/Flex automation for your machine. If the automatic instrumentation does not work, you can follow these steps to achieve the same result:
- Install the Adobe Debug Flash Player on the machine on which you want to record and execute Ranorex test scripts and for all browsers you want to test with. The respective installers are available on Adobe’s download page.
- Open your user profile directory %UserProfile%, by opening Windows Explorer and copying the string %UserProfile% into the address bar.
- Check if the ‘mm.cfg’ file exists.
- If the file exists, open the file and verify that the first line of code includes your current preloader location (Ranorex X.X might change after upgrading to a new version!).
-
If the file does not exist, create a new file called ‘mm.cfg’ in your user profile directory and insert the following line of code:
C:Program FilesRanorex X.XBinRanorexAutomation.swf - Replace ‘C:Program FilesRanorex X.XBinRanorexAutomation.swf’ with the preloader location of your Ranorex installation.
-
Enable the logging mechanisms of the Adobe Debug Flash Player, which might be helpful if you have any problems with this kind of instrumentation, by adding the following line of code to your ‘mm.cfg’ file:
TraceOutputFileEnable=1This creates a log file at the following location: C:Users[username]AppDataRoamingMacromedia Flash PlayerLogs
- If you run your application from the local drive, add your output directory to the trusted locations of Flash Player as follows:
- Open the Settings Manager.
- Add your project output directory
Automation Lib
Adobe Flex
Load the Ranorex Lib into your Flex application as follows:
- Open your project in Adobe Flash Builder.
- Right-click the project and select Properties.
-
Under Flex Compiler, add the following to the compiler arguments to add the RanorexAutomation.swc file (located in the Bin directory of your Ranorex installation):
-include-libraries "C:/Program Files/Ranorex/Bin/RanorexAutomation.swc" -
Append the following code to your ‘applicationCompleteHandler’ function:
import Ranorex.RxAutomation; RxAutomation.Init(); - Compile and run the 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:
- Open the Settings Manager.
- Add your project output directory
Adobe Flash
Load the Ranorex Lib into your Flash application as follows:
- Open your application in Adobe Flash CS4/CS5.
- Open the Publish Settings dialog (File > Publish Settings).
- Navigate to Flash > Script > Settings… > Library Path.
- Click Browse to SWC file and select the RanorexAutomation.swc file in the Bin directory of your Ranorex installation.
-
Press F9 to insert the following code into 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); } } - Compile and run the 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:
- Open the Settings Manager.
- Add your project output directory.
Module
Adobe Flex/AIR
Load the Ranorex Module into your Flex/AIR application as follows:
- Start Adobe Flash Builder and open your workspace
-
Append the following code to your ‘applicationCompleteHandler’ function or initialization code:
For Flex 3:
Flash/Flex
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:
Flash/Flex
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"));
- 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 Flex/AIR application from the local drive, add your output directory to the trusted locations of Flash Player as follows:
- Open the Settings Manager.
- Add your project output directory.
Adobe Flash
Load the Ranorex Module into your Flash application as follows:
- Start Adobe Flash CS3/CS4/CS5 and open your application
-
Insert the following code into 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:
- Open the Settings Manager.
- Add your project output directory
How to read/set attributes and styles
You can read/set common attributes (for example, the checkstate of a checkbox) directly by using the adapter as follows:
Flash/Flex
// 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");
</flexelement>
To access custom attributes and styles, you first have to load your Flex item as a FlexElement to read your attributes. Here’s an example:
Flash/Flex
// 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");
</flexelement>