Monday, October 4, 2010

Testing Flex with Selenium

The purpose of this post is to explain the differences between Flex and Flash w.r.t to testing and how to test the same with Selenium. This follows the previous post of Testing Flash with Selenium.

Flex and Flash both based on ActionScript. Flash coded using AS3 and complied into SWF file. In Flex, actions are coded in Java and converted into AS3 and complied into SWF file. For Java developers, Flex offers a option to code in Java rather than learning AS3. Actually, building a Flex app is complex than Flash app, however, discussing that is out of scope of this post.

As we saw in here, External Interface is the only JavaScript can interact with ActionScript. In Flex, it is possible to add ExternalInterface call backs for all the actions when compiling with a FlexUISelenium API. So it takes away the burden of manually adding and removing the call backs in the case of Flash.

The following steps describe how to install and use FlexUISelenium  in a few simple steps.
  1. Download and install Selenium RC  
  2. Download Selenium Flex API, and rebuild your Flex application with SeleniumFlexAPI.swc 
  3. Download FlashSelenium and add to your test project 
  4. Download FlexUISelenium  and add to your test project 
  5. Write and run your test cases against your Flex applications 

So if you use Flex instead of Flash, is that possible to test that in Selenium easily? No. If the API can't add ExternalInterface ability to all of you actions in the UI, then you need to review the code  manually and add all those things. Again, we left with the manual option of adding the interaction between ActionScript and JavaScript. How do we know, this method didn't add those callbacks? Only when recording the tests.

In the end there is no silver bullet for testing Flex/Flash apps in Selenium. Manual work is needed to add the ability of interaction in these apps.

PS: SauceLabs Flex Recorder claims that there is no need to recompile the Flex app in order to test. I haven't tried that so can't comment about that.

Thanks to my friend Vinod for helping me in this.

Happy Testing


raja's shared items

My "Testing" Bundle