Top Rounds
[Hide Navigation]

Sahi Flex Support - sfl ·


Sahi Pro provides support for automation of flex applications. Before automating your flex application
you will first need to compile your swf with the correct version of sfl.swc

Eg. If your application is compiled with Flex 4.0, use sfl4.swc

Please find the corressponding sfl.swc at sahi_pro/sfl directory.

Compile with sfl.swc using command line

You can compile your flex application with sfl using the following command (Change sfl version as

mxmlc yourapp.mxml -include-libraries+=sfl4.swc --output=yourapp.swf

Compile using Ant

You can use this ant target to compile your flex application with sfl.

<project name="sahiTest" basedir="." default="build-flex-app">
    <!--classpath : path of flexTasks.jar-->
    <taskdef resource="flexTasks.tasks" classpath="lib/flexTasks.jar" />
    <property environment="env"/>
    <!--FLEX_HOME env value should be set-->
    <property name="FLEX_HOME" value="${env.FLEX_HOME}"/> 
    <target name="build-flex-app" >
        <mxmlc file="Sample.mxml" keep-generated-actionscript="false" 
incremental="false" fork="true" append="true" verbose-stacktraces="true" > 
            <load-config filename="${FLEX_HOME}/frameworks/flex-config.xml"/>
            <!--dir: dir path of sahi flex compilation libraries-->
            <compiler.include-libraries dir="flex-addons" append="true">
                <include name="sfl4.swc" />
            <source-path path-element="${FLEX_HOME}/frameworks"/>
            <compiler.source-path path-element="src"/>

Compile using Adobe Flash Builder (Add SWC files to Flex Builder projects)

  1. In Flex Builder, select your Flex project in the Navigator.
  2. Select Project > Properties. The Properties dialog box appears.
  3. Select Flex Compiler in the tree to the left. The Flex Compiler properties panel appears.
  4. In the “Additional compiler arguments” field, enter the following command:
    bc. -include-libraries “sfl4.swc”

In Flex Builder, the entries in the include-libraries compiler option are relative to the Flex Builder installation directory.

The default location of this directory on Windows 32 bit is C:\Program Files\Adobe\Flex Builder and on Windows 64 bit is C:\Program Files(x86)\Adobe\Flex Builder

After compilation refresh the browser cache, to make sure that the modified yourapp.swf is available.

Recording a flex application

From the dashboard, open any browser and navigate to your flex application.
Press ALT and double click on the document window of the page which you want to record. Sahi’s Controller window will pop
up. You can now start recording your Flex application.


Ctrl + hover (to get a flex element’s accessor) will work only if the Flex object is in focus. To do
this, you will have to first click on the Flex object.
Flex APIs are different from the normal JavaScript APIs.



For Recognizing Custom Components:

Sahi, by default adds most of the default mx and spark components. To enable Sahi to recognize custom components in your application,

edit /userdata/config/user_extensions.js as,

SflWrapper.prototype.addCustomMetaData = function(){
      this.addMetaData({qn: "<package-name>::<component-name>", 
attributes: ["label", "text", "name", "automationName", "toolTip", "id", "autoGeneratedName", "index"], 
action: "click", value: "label"});

For example:

<package-name>: mx.containers
<component-name>: Panel

Relational operators in SFL

Currently, SFL supports only near and inside APIs.

_setValue(_f("fid").textinput("u").near(_f("fid").label("User")), "ram");
_setValue(_f("fid").textinput("u").inside(_f("fid").vgroup("SettingsPanelView")), "ram");

Known Issues:

1) For the CTRL-Hover to work, one needs to click on the Flex app and bring it in focus
2) Drop down values are not automatically recorded (it is currently recorded as a click). Work-around: CTRL-Hover on the drop down, and from the Controller, click the “Set” button. This will create a _setSelected statement in the “Evaluate Expression” box. This can be copied over to your script.
3) File upload/download are not currently supported.

Tips on usage:

The flex recorder in Sahi is not as sophisticated as the web recorder.

To introspect and identify elements, one can use the Evaluate Expression box. Ctrl Hover on any Flex element. It will populate something like


1) One can see all attributes of the textinput field by evaluating


2) To fetch any property of an object, use .get





3) To see which Flex components make up a particular component, use introspect()


will show a list of all elements inside the textinput field.

The output may look something like:

textinput0>Panel4>username>UITextField8:mx.core::UITextField #abcd 

4) To see all elements in a flex component, (especially when an element is not identified) use


5) To record comboboxes, first CTRL Hover on the element,
then change the “Value” on the Controller and click “Set”.
Use the _setSelected statement which is visible in “Evaluate Expression” box.

6) To check if an element exists, use .exists()


7) To check if an element is visible, use .isVisible()


8) To get data from a graph or grid, it is easier to get the dataprovider of the object
and verify that the data is correct.
To get the dataprovider, do


This will return a JSON string. To get an object out of it, use

var obj = eval("(" + _f("mymovie").datagrid(0).get("dataProvider") + ")");

obj will now be an array of objects, which looks something like this:

[{"balance":"1000","category":"Personel Care","date":"15/12/2010","description":"ATM Fee",

9) SFL supports indexes and regular expressions just like normal Sahi APIs.


Top Rounds