We get a lot of customer requests about Flash automation, Selenium, and BrowserMob. Because our load testing and website monitoring services uses real browsers, complete with Flash 10, we can do things no one else can do, like run a load test with hundreds of Flash runtime environments driving traffic on your site.

However, while our infrastructure allows for extremely unique Flash testing support, it’s not perfectly streamlined (yet). While we are hard at work on making Flash support for Selenium and BrowserMob significantly better, at this time some work is required by Selenium users before you can get started.

Specifically, the first question that must be answered is: what automation technique do I want to employ? There are two distinct ways to go:

  • Native mouse & keyboard integration – good for situations where there is minimal Flash interaction required
  • API-level integration – good for situations where there is a lot of Flash interaction required

Native mouse & keyboard integration

Let’s talk briefly about native integration. This is where a mouse movement, mouse click, or keyboard action is simulated at the operating system level. It reproduces the most realistic user simulation. However, it can be very brittle, as it has limited ways to “read” from the screen and validate that functionality worked correctly.

Presently there is no great Selenium-only solution here. There are commercial functional testing products such as eggPlant, but nothing on the load side of things. BrowserMob does have, however, the ability to interact with the operating system using native key events and coordinate-based mouse interaction.

This feature is perfect for those who want to fire off one or two simple interactions, such as clicking on a movie’s “play” button or interacting with a confirmation dialog. If this is all you need for your Flash or Flex integration, please contact our support team and we’ll gladly help you get your script working using this unique API.

API-level integration

For applications that have much more complex Flash/Flex user interfaces or applications that are 100% Flash-based, we don’t recommend native events as they can be brittle and difficult to confirm that the desired functionality worked. Instead, we recommend interacting with your Flash applications using API-level integration.

Important: to do this type of automation you must be able to recompile/modify the underlying Flash object(s). If you cannot do this and require full “black box” style automation, we suggest you consider native automation or you consult with the authors of the original Flash component.

How you proceed from here depends on whether you are using Flash or Flex. The reason is that Flex exposes some automation APIs that you will otherwise have to reproduce if you are using Flash-only.

Flash automation with ExternalInterface

If you are using low-level Flash, your automation options are a little more limited:

  • Using ExternalInterface directly – no 3rd parties, but might requires the most programming
  • Using FlashSelenium – an open source library to make ExternalInterface callbacks easier to call

We recommend you first start off with ExternalInterface directly, as FlashSelenium is really just a thin wrapper around ExternalInterface. While it’s convenient, we think doing it by yourself once is an important learning experience.

To get started, we recommend reading the ExternalInterface documentation by Adobe. The basic idea is that within your Flash component you execute this code:

ExternalInterface.addCallback("doSomething", doSomething);

This exposes the function doSomething such that it can be executed by JavaScript. Fortunately, because Selenium can execute JavaScript using the getEval, storeEval, assertEval, etc commands, we’re in luck:

var jsExpr = "window.document.getElementById('myFlashObjId').doSomething()";
var something = selenium.getEval(jsExpr);
if (something == 'blah') {
   // throw an error, we weren't expecting 'blah'!
}

Using this technique, you can begin to expose ActionScript functions that can be used to automate the Flash component and validate that the right behavior took place.

Flex automation with Selenium-Flex

If you’re using Flex, automation should be quite a bit easier. Thanks to Selenium-Flex, you don’t have to spend time exposing dozens of functions via ExternalInterface. Instead, just compile your Flex application using the Selenium-Flex library:

  1. Copy the sfapi.swc file in to your project (ie: the lib directory)
  2. In your IDE/build system, ensure that the library is included (ie: -include-libraries)

That’s it! Now the next time you build your Flex app it’ll automatically have a whole bunch of functions already created. Even better, you don’t have to do all that getEval mumbo-jumbo we did for Flash testing. Instead, thanks to another open source project called FlexUISelenium (which works in concert with Selenium-Flex), the getEval stuff is abstracted away so that your tests look like this:

flex.type("2").at("arg1");
flex.type("3").at("arg2");
flex.click("submit");

If you’re doing functional programming using Java or some other full-blown programming language, you can get started with FlexUISelenium today. If you’re looking to load test or do website monitoring with Selenium, we are in the middle of adding FlexUISelenium support to the BrowserMob API. We are looking for beta participants right now, so contact us if you’re interested.

A note about recording support

Currently, none of the open source solutions referenced here support recording interactions from within Selenium IDE. While not Selenium-compatible (yet), FlexMonkey is a very good open source Flex record and playback functional testing framework. We have plans to integrate Selenium and FlexMonkey in the future, including record support through Selenium IDE.

In the meantime, you will need to write each Selenium command by hand. This means that you’ll need to be aware of the IDs of all the elements you wish to interact with. Once you know those IDs, you can write the code that issues clicks or types on the component.

Update December 11, 2009 – For more information, we also recommend this Adobe Developer Connection article by Paulo Caroli and Henrik Lindahl: Writing and running functional tests for Flash with Selenium RC.


17 Responses to “Flash and Flex automation options using Selenium”

  1. Hi,

    Are you aware of the timeline , by when Selenium IDE will have support for recording Flex apps?

    Thanks,
    Santosh

  2. Santosh,
    I don’t know any time frames, but there are some very interesting things happening with integration between FlexMonkey and Selenium that might be out in the next few weeks. Keep a look out on this blog and we’ll be sure to announce anything important!

    Patrick

  3. Hi
    Is flexmonkey and Selenium is integrated now?
    Rajeev

  4. Yes Rajeev. Flexmonkey has come up with an add-on “Flexmonkium” for Selenium IDE, which enables capture/playback Flex apps.

    However, do not get excited too much, the JUnit code Selenium generates, has nothing but embedded Selenese commands. :) Not bad though.

  5. How to find flash elements of we applications using selenium rc with visualstudio as a platform

  6. I just wonder is there any way of implementing the Flex automation using selenium2 for C#. If yes could you please provide the implementation technique for flex automation in selenium2

  7. Hi,

    Can any buddy tell me how can i use selenium IDE and selenium RC for Flex automation

    i understood the above comments but i do not have access to Application Library or i do want to change any thing on my server side

    can some buddy tell me how can i use selenium without performing following
    1.Copy the sfapi.swc file in to your project (ie: the lib directory)
    2.In your IDE/build system, ensure that the library is included (ie: -include-libraries)

    I just have my flex application URL which i want to automate
    Please suggest

    Regards
    Anup

  8. Anup,
    You must do those steps if you wish to automate Flex. Sorry.

    Patrick

  9. Thanks Patrick For your Reply.

    But in future if you come across such solution please do post it

    Regards
    Anup

  10. Hi Anup,
    If u r on a opensource, i’ll be more than happy to help you over teamviewer.

  11. Hi i want to automate my flex application using selenium IDE and SeleniumFlexAPI but i am not able to do it, can any 1 help me in this regard. I will tell u the steps what i did,

    1. Downloaded SeleniumFlexAPI and added the SeleniumFlexAPI.swc file in my flex project under libs directory.
    2. I added the downloaded user-extension.js file in my Selenium IDE 1.0.10.
    3. I had compiled my flex applications with compiler argument as -include-libraries “libs\SeleniumFlexAPI.swc”.
    4. I executed my application on to tomcat server but it is not identifying any of the object.

    Thanks in advance
    Mandar

  12. Hi i want to automate my Flash application using selenium IDE and Selenium Flash but i am not able to do it, can any one help me in this regard. I will tell u the steps what i did,

    1. Develop a Flash Application Using FlexBuilder 4.
    2. I added the downloaded FlexMonkium in Selenium IDE 1.0.10.
    3. I executed my application on to tomcat server but it is not identifying any of the object.

    So please guide me that what steps i have to follow to capture the Flash Object…

    My email-id is: amit.bmsmca@gmail.com

    Thanks
    Amit Kumar

  13. I am trying to run colors.html Flash app.
    I am able to run it successfully. But my browser comes and goes just like that. And i am not able to see the result.
    I am using FF 3.6

  14. Hi

    I am automating Flex application using Selenium RC.
    Selenium is identifying all the Flex objects except Custom Components.

    Can anyone suggest me, how to do that?

  15. Yes, I too have same query as above Mandar has mentioned.
    I have installed all things proper, yet unable to record the script for flex objects in Selenium IDE. However, I have I added SeleniumFlexAPI.swc in project & deployed it then I am able to see the separate lebels for every elements on flex screens like – link,button, textarea etc.
    Now wanted to used those labels for recording purpose. can anyone please help me, how can use those labels for selenium IDE recording? Even its ok to add flexcommands by hand in selenium IDE window.

    Thanks!

  16. Thanks

  17. HI

    I am working on automating Flex Application using Selenium Remote Control (RC). i was successful in automating most of the thing except TIMELINE which is main part in our application.

    Has anyone has investigated on this new feature to say that Selenium will work with TImeLine component or Not?

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

 

© 2012 The BrowserMob Blog Suffusion theme by Sayontan Sinha