Wednesday, March 16, 2011

Selenium with Flex

Recently I just got the chance to check the selenium support with Flex. And after few minutes spending on google I finally find almost everything required for to test flex application.
To provide flex support to selenium is easy, you just need to add few more JAR files but there is a minor problmes too.
  1. You require your developers to rebuild your application with provided library file (SeleniumFlexAPI.swc) by selenium flex
  2. It's not working with Firefox 3.0 or greater version (at least it didn't work with me !!, I am still searching for the solution)

Now let's see how to test flex application with selenium step by step.
  1. Rebuild your flex application
    • Download the zip file from here and extract the zip file
    • In FlexBuilder, add the SeleniumFlexAPI.swc in the /src folder, then build your application with -include-libraries SeleniumFlexAPI.swc as the additional compiler argument
  2. Include the JAR files in the the project
  3. Before you began coding you require following jar files in your build in addition to selenium-java-client-driver.jar
    flashselenium-java-client-extension.jar
    flex-ui-selenium.jar
  4. Write the code
    okay let's write the code.. no no no hang on !! before we write the code we need to identify the elements of the flex application.  I am using following add-on of Firefox to identify the elements.
    FlashFirebug (this is actually a extension of the firebug add-on)
  5. /**
     * @author Gaurang
     */
    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 TestFlex {
     Selenium selenium;
      private FlexUISelenium flexUITester;
     @Before
     public void setUp() throws Exception {
      selenium = new DefaultSelenium("localhost", 2323, "*chrome", "http://qtp-help.blogspot.com");
      selenium.start();
      while(selenium.isElementPresent("myInput"))
      Thread.sleep(1000);
      selenium.open("/2011/03/flex-example.html");
      flexUITester = new FlexUISelenium(selenium, "selenium_demo");
     }
     
     @Test
     public void test() {
      //Enter text
      flexUITester.type("Gaurang").at("myInput");
      flexUITester.click("myButton");
      assertEquals("Gaurang", flexUITester.readFrom("myText"));
     }
    }
    
    

1 comments:

Prashanth The J said...

Hi Gaurang,

Could you post the same actions performed with ruby?

Post a Comment