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
You can compile your flex application with sfl using the following command (Change sfl version as
needed)
mxmlc yourapp.mxml -include-libraries+=sfl4.swc --output=yourapp.swf
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" />
</compiler.include-libraries>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.source-path path-element="src"/>
</mxmlc>
</target>
</project>
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.

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.
NOTE:
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.
Eg.
_f("flex_app_id").textinput("username2")
Sahi, by default adds most of the default mx and spark components. To enable Sahi to recognize custom components in your application,
edit
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
Currently, SFL supports only near and inside APIs.
Example:
_f("fid").textinput("u").near(_f("fid").label("User"))
_setValue(_f("fid").textinput("u").near(_f("fid").label("User")), "ram");
_f("fid").textinput("u").inside(_f("fid").vgroup("SettingsPanelView"))
_setValue(_f("fid").textinput("u").inside(_f("fid").vgroup("SettingsPanelView")), "ram");
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.
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
_f("sampleId1").textinput("username")
1) One can see all attributes of the textinput field by evaluating
_f("sampleId1").textinput("username").listProperties()
2) To fetch any property of an object, use .get
Eg.
_f("sampleId1").textinput("username").get("text")
or
_f("sampleId1").textinput("username").get("label")
3) To see which Flex components make up a particular component, use introspect()
Eg.
_f("flexId").textinput("tId").introspect()
will show a list of all elements inside the textinput field.
The output may look something like:
textinput0>Panel4>username>HaloBorder17:mx.skins.halo::HaloBorder
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
_f("sampleId1").introspect()
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()
_f("mymovie").datagrid(0).exists()
7) To check if an element is visible, use .isVisible()
_f("mymovie").datagrid(0).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
_f("mymovie").datagrid(0).get("dataProvider")
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",
"price":"1000","quantity":"1000","payee":"ABC","amount":"1000","datePaid":"15/12/2010",
"status":"success","action":"buy"}]
9) SFL supports indexes and regular expressions just like normal Sahi APIs.