How to test Flex application using Selenium RC?

How to test flex application using Selenium RC?

Testing Flex applications was difficult because the logic or behavior is encapsulated from the browser. Selenium RC uses JavaScript to communicate with the browser. Flex External Interface provides a mechanism for which you can use JavaScript to call an ActionScript function in a SWF file embedded in an HTML page. Therefore, we use FlexSelenium, a Selenium RC client extension that uses JavaScript as the medium between Selenium RC and the Flex application.
You can also test flex application by having a flex monkium plugin in selenium IDE. You need to compile your client application with sfapi.swc and automation_monkey.swc and the flex libs. This becomes your application to test. You can record your test and convert that into any format which you are comfortable in.
Recently I just got the chance to test one Flex application using selenium. To provide flex support to selenium, you just have to add few JAR files. But for this you need to rebuild your application with provided library file (SeleniumFlexAPI.swc) by selenium flex. 

Below are the steps to test flex application using Selenium RC.
  1. Rebuild your flex application with SeleniumFlexAPI.swc
    Download the “Selenium-Flex API” zip file and extract the zip file. In FlexBuilder, add this SeleniumFlexAPI.swc in the /src folder, then build your application with -include-libraries SeleniumFlexAPI.swc as the additional compiler argument.

  2. Add JAR files in the project
    Download “Flash Selenium Java client extension” and “Flex UI Selenium” jar files. Now Right click on Project name in Eclipse and Select “Build Path >> Configure Build Path >> Library Tab”. Add these jar files by selecting “Add External Jar files” button.

  1. Write Selenium Script
    Before we write the script in Selenium RC we need to identify the elements of the flex application. So for this use FlashFirebug (extension of the firebug add-on) Firefox add-on to identify the elements.



    Selenium Script:
     @author Software Testing Diary

    package practice;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import static org.junit.Assert.*;
    import com.thoughtworks.selenium.DefaultSelenium;
    import com.thoughtworks.selenium.FlexUISelenium;
    import com.thoughtworks.selenium.Selenium;

    public class flexSelenium {
        private final static String OPEN_URL = "";
        private final static String OPEN_PAGE = "2012/07/how-to-test-flex-application-using.html";
        private Selenium selenium;
        private FlexUISelenium flexUITester;
        public void setUp() throws Exception
            selenium = new DefaultSelenium("localhost", 4444, "*chrome",OPEN_URL);
            flexUITester = new FlexUISelenium(selenium, "selenium_flex.swf");
         public void test()
        flexUITester.type("Software Testing Diary").at("myInput");"myButton");
        assertEquals("Software Testing Diary", flexUITester.readFrom("myText"));
        public void tearDown() throws Exception

    Thanks and Regards,
    Prashant Vadher | QC Engineer 



Post a Comment

Design by Prashant Vadher