Skip to Content
*Test Automation for Web Flex Applications* Selenium is an open-source testing tool for web applications. Selenium tests run directly in the web browser itself, mimicking  real user workflows. The only drawback is selenium server alone does not support Flash or Flex Applications.  Alternatively selenium Remote Control is a tool that allows you to launch browser sessions and run selenium tests against those browsers with Flex applications.                     In this, the Selenium  RC server acts as an intercepting proxy for the browser.FlashSelenium, a selenium RC client extension that uses JavaScript as the conduit between Selenium RC and the Flash application (i.e., .swf  file)                                       test                                                                Fig: Flash with selenium This blog series will show you how to start automating flex applications , and this  is split into four sections.: 0.1. {code:html}Instrumenting the swf file{code}0.1. {code:html}Adding flex spy library-helps easy automation{code}0.1. {code:html}Configuring the workspace.{code} 0.1. {code:html}Building/running  the automation code.{code}* * h2. Instrumenting swf file:                                             Instrumentation is a process of making sure that the flex application controls are available for the selenium. For making a Flex application instrumented firstly  open the flex application in Flex Builder or Eclipse, include the flash-selenium.swc file in the lib directory of your flex project and add the arguments required, to do this  1. Go to you project properties i.e. right click on the project and go to properties 2. Click on the “Flex Compiler” option from the list 3. Add the following text to the “Additional compiler arguments” -include-files -include-libraries “libs\SeleniumFlexAPI.swc”  Flex Builder Compiler Settings The text “libs\SeleniumFlexAPI.swc” may need to be “..\libs\SeleniumFlexAPI.swc” depending on the relative path of your main MXML file. If you find nothing works try putting the entire path to the SeleniumFlexAPI.swc file. Then compile and build the Flex project,this makes the flex application selenium instrumented.If you are launching the application from the webserver, make sure to replace the complied swf file into the web-server localhost folder.* * h2. Configuring the workspace:  The automation for the selenium instrumented  flex application,can be done using junit or nunit,here we are using junit to implement the tests.In the eclipse workspace create a new java project ,add all the required flash-selenium, flex-selenium  and junit 3 or junit4 jar files.  Fig:Eclipse work space                                                                           Fig: Eclipse work space Each testcase can be implemented as individual  junit test case class and  invoking of the test case classes  can be done using the junit testsuite class. A selenium server should be in running state before starting the tests. * * h2. Adding flex spy library-helps easy automation : Flex-Spy is a tool helps in identifying the properties of the flex components,follow these steps to setup Flex-Spy in your Flex project : * On the left side of the Properties window, select *Flex Library Build Path*. 0.1. On the right side of the Properties window, select the *Library path* tab. 0.1. Click the *Add SWC…* button 0.1. Select the flexspy.swc file that you downloaded (from the Downloads section) and click *OK*. *Drawbacks:* 1. Flex-spy does not identify the properties of Flex popup windows. * * h2. Building/running  the automation code:    Once the workspace is setup open the junit test case class and start the code implementation. Any component of the flex application in java code can be identified using the id property; getting any property of flex elements can be done using the external tools like Flex-Spy.                                                                      The different functions that are supported by Flash-selenium and flex-ui-selenium are *doFlexClick , doFlexSelectIndex, getFlexText, getFlexEnabled, getFlexExists, doFlexSelectComboByLabel, call, click, type, isChecked* etc… | Function Name | doFlexClick | | Description | Clicks a standalone button or a button that resides on a ButtonBar or Accordion control | | Target | | *Id* *if clicking a stand alone button

*Button Label *if clicking a button on a ButtonBar or Accordion control

Returns

Error message if command fails

 

Function Name

doFlexSelectIndex

Description

Select a list based object option based on the index if the menu items

Target

*Id*

Value

*Selection Index* The index of the listed items to select Indexes start at 0 An index of -1 means no listed item is selected If an index specified is too large, the last item on the list is selected | Returns | Error message if command fails |   | Function Name | doFlexSelectComboByLabel | | Description | | Select a list based object option based on a string provided in the value. Values *are *case-sensitive

List based controls include Lists, Horizontal Lists and ComboBoxes

Target

*Id*

Value

*Selection Index*

The index of the listed items to select

Indexes start at 0

An index of -1 means no listed item is selected

If an index specified is too large, the last item on the list is selected

Returns

Error message if command fails

 

Function Name

getFlexText

Description

Gets the text or label value from a component

Target

*Id*

To assert a text values in Text, TextInput, TextArea, Labels, etc… use:

*Eg: myLable* | Value | Text Value | | Returns | Error message if command fails |   While intialization of FlashSelenium and FlexUISelenium  pass the instrumented swf file name as argument ,for example +sele+.start(); +flashApp+ = *new* FlashSelenium(+sele+, “InstrumentedSWF”); +flexUITester+ = *new* FlexUISelenium(+sele+, ” InstrumentedSWF”); And use all the function & methods available for performing  and invoking the flex components to automate the web application.                                                Fig: Junit Testcase class Assertions can also be used for verification of values. Eg:                                        Fig: sample Junit test case class using assertions Individual test cases written above can be controlled in the junit test suite as below:  Fig:Junit Testsuite Once the coding is done start the selenium-server  and  run  java project as Junit test. Fig: Selenium server                                                                          Fig: Selenium server   Fig: Junit test runner                                                      Fig: Junit test runner

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply