Wednesday, August 18, 2010

Selenium Testing with FlexPilot

I continued my quest for a solution to create automated tests using seleniumRC and C# and this time I took a look at this new project called Flex Pilot.

FlexPilot is a open source testing tool that integrates with selenium,  it has a bootstrapper to make the application testable, it is able to use a selenium IDE recorder, and you can access elements using chain syntax (like accessing with xpath).

Here is what I did to start building tests with flex pilot:

  • Rebuilded flexpilot: source is http://github.com/mde/flex-pilot/archives/master and excecuted build.py this will update FlexPilot.swf and FPBootstrap.swf  located under org/flex_pilot folder (place this file where the app is located)
  • Copied the content from src/org/flex_pilot folder to the flex's app libs folder example C:\source\MyAppInFlex\libs
  • Imported Bootstrap in the flex app
    import org.flex_pilot.FPBootstrap;

  • Set FPBootstrap.flex_pilotLibPath the path on the server where FPBootstrap can find FlexPilot.swf. The Loader fetches FlexPilot.swf via a Loader class.

    FPBootstrap.flex_pilotLibPath = '/flash/org/flex_pilot/FlexPilot.swf';

  • Initialize FPBootstrap this fetch and load FlexPilot.swf, and gives FlexPilot Flash a context to use for testing. This context is usually a reference to app’s Stage.

    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:local="*" creationComplete="init() 
    applicationComplete="
    initFlexPilot()">
    ......
    <mx:Script>
    <![CDATA[
    ...............
    import mx.utils.ObjectUtil;
    import org.flex_pilot.FPBootstrap;

    ...............
    private function initFlexPilot():void
    {
    FPBootstrap.flex_pilotLibPath = 'FlexPilot.swf';
    FPBootstrap.init(stage);
    }
    ......

  • Compiled application: mxmlc -source-path=. -source-path+=../libs MyAppInFlex.mxml -o MyAppInFlex.swf
  • If present, remove tags like <noscript> around the flex object in you html.
  • If the configuration is working Firebug will return “function” when calling document.getElementById('MyAppInFlex').fp_click 
  • This is the “hello world” example of a test method on c#

    [TestMethod]
    public void TestMethodFlexPilot()
    {
    selenium.Open("http://localhost/testapp.html");
    selenium.RunScript("document.getElementById('MyAppInFlex').fp_type({name:'usernameTextInput', text:'Flex Pilot'})");
    selenium.RunScript("document.getElementById('MyAppInFlex').fp_click({name:'secureCheckBox'})");
    }

FlexPilot has seleniumRC client drivers available for java, phyton and rubi (no c# client driver available yet)

5 comments:

  1. Hi, thanks for your post. It's helpful but also leaves a lot of open questions (at least for me). First, where does the RunScript() method come from? That's not standard Selenium unless it's something that was recently added.

    ReplyDelete
  2. Hi, the RunScript method is part of selenium rc (version 1.0.3)

    you will see it in DefaultSelenium class method public void RunScript(string script);

    ReplyDelete
  3. Hi,
    Thanks for the great post. I am new baby in Flex automation using Selenium. Could you please tell me how to update Selenium RC client server for using Flex Pilot. I am using Java client.

    ReplyDelete
  4. Hi Anoop,

    there is a client api available for Java on https://github.com/admc/flex-pilot-x/tree/stable/client/java

    this is what I am doing for c# I created a class that extends DefaultSelenium

    public class FlexPilotDriver : DefaultSelenium
    {

    and added flexpilot commands, for example

    public void FlexClick(string appID, string flashLoc)
    {
    commandProcessor.DoCommand("flexClick", new String[] { appID, flashLoc });
    }

    and the test code creates an instance of FlexPilotDriver

    you will need to run selenium server using flexpilot's user extention

    for example

    selenium-server-1.0.3\selenium-server.jar -port 4446 -userExtensions user-extensions.js

    ReplyDelete
  5. Hi Mariange,

    I am new to flex application automation, it would be great if you explain it from the beginning like.
    1. What is the exact path we set into FPBootstrap file for flexpilot.swf if we have the same under C:\Users\Admin\Adobe Flash Builder 4.5\TestFlex\bin-debug path.
    2. Do we need any other file so that flex pilot can read the methods.

    Also I am getting "[info] Exception, method was not accessible" information when open IDE do i need to perform some troubleshoot to overcome this issue.

    It would be great if you can share step by step approach.

    Thanks
    Tapashwani Anand

    ReplyDelete