Saturday, October 23, 2010

Automating MyAppInFlex.swf – Useful FlexPilot commands

I continue automating my Flex application with FlexPilot. One clear advantage I found when using FlexPilot is that I was able to access more of the UI elements of a complex Flex interface. The other tools I tried weren’t picking all those elements, but I must admit that I didn’t investigate further.

An interesting feature is FlexPilot’s chain syntax, that allows to access flex UI elements by different properties, like id, label or text. Another feature I liked is easier integration to work with selenium RC and selenium IDE.

Below some usage examples to create automated tests for MyAppInFlex.swf, and also serve as a quick reference on how to interact/access the flex UI.

Click on a Button

The easiest way to access an element is using the element’s id, for example click on a button:
selenium.flexClick("id=MyAppInFlex", "chain=id:okButton");

If the button you are trying to access doesn't have an id, you are able to find it using the label property:

selenium.flexClick("id=MyAppInFlex", "chain="id:buttonBar/label:Search");

Access an element on a Grid

Click an element that has an specific value on a Grid
selenium.flexClick("id=MyAppInFlex", "chain="id:userGrid/name:AdvancedListBaseContentHolder*/name:AdvancedListBaseContentHolder*/text:Maria Marcano");

Check the value on a TextInput

Check a textbox has a specific value
selenium.flexAssertProperty("id=MyAppInFlex", "chain="id:emailTextBox, validator=text|", );

To improve the application testability, add id’s to the objects you want to access. This also applies for web application in general (accessing elements by id’s is faster than processing xpath expressions).

Some limitations

Elements on a grid can’t be accessed by position, for example click on the first/second element on a grid.

I’ve been experiencing some issues with some application builds that prevent the use of the flex explorer and recorder (reported the bug, hopefully it gets fixed soon). You can still run the tests, just not using those tools to capture the elements.


  1. Hello! I'm curious whether you got a chance to play with Flex Monkey/ FlexMonkium tools at all. I'm choosing between Gorilla Logic's test tools and Flex Pilot, and have found both to be reasonably easy to integrate with Selenium.

    I'd be interested in anything you have to say regarding how easy it is to create an abstraction layer for common testing tasks with FlexPilot.

    So far it looks much better than the alternatives, in particular because it's easier to test in production environments. The bootstrapping aspect is lovely. All the other tools out there have relatively bulky additions to the Flex app library.

  2. Hello @Nickname, I haven’t take a look at Flex Monkey / FlexMonkium, a coworker played a bit with the tool but was finding issues accessing some UI elements (I reviewed a bit selenium flex api and had issues accessing elements as well).

    About the test organization, yes it is easy to create an abstraction layer (like you do using selenium RC), for example I placed all FlexPilot commands on a class called FlexPilotDriver and I am following the page object pattern (represents the screens of your web app as a series of objects)

    you can have write tests like this:

    var adminPage = homePage.Login(username, password);

  3. Hey this Sushma here … i am working on selenium-flex automation ….and i wonder that for selenium we can give the xpath if there is no unique identifier for the object . But in flex how to click on a object which has no unique identifier set but has a label value
    ex:“doFlexClick”, “?”,”?”);
    Your help is much appreciated .. urgent !!!

  4. hey i tried different ways and i got the solution

    .... but now iam struck at the point when the items are rendered by a service provider ...