Hey there! any question in your mind? Ask It Now!.
My Account

How to handle flex in selenium web driver?

+10 votes
7,689 views
asked in QA Automation Testing by tester (1,550 points)
retagged by Bhartesh
Hello guys i am trying to handle flex in selenium but not getting any solution please tell me how can i handel flex.

Thank you!

2 Answers

+8 votes
answered by seleniumGuru Expert (4,570 points)
selected by Bhartesh
 
Best answer

To automate flex using selenium you have to follow these steps :

  • You have to download selenium flex API .
  • You will get a SeleniumFlexAPI.swc file here.

    a.  Now add this SeleniumFlexAPI.swc file into your libs folder (This folder would be in your project or check your repo and search libs folder).

    b. After adding that file in libs folder now you will have to compile your code so that SeleniumFlexAPI.swc file      can include in code , for compiling you need to add lib path in flex compiler like this :

                                                       -include-libraries "libs\SeleniumFlexAPI.swc"

Now Compile the code.

Next point 3 is in the first comment please follow that after executing these above steps.

commented by Bhartesh (2,630 points)
Hi Eddy,  First of all, this SWF/SWC file should be added to you flex project which needs to be automated . Make sure you are adding it to correct project.

And for how to compile, pls refer this link : http://help.adobe.com/en_US/flashbuilder/using/WSe4e4b720da9dedb5-1a92eab212e75b9d8b2-7ffe.html
commented by Kushal
Hi I'm getting following error, here Selben is my ID name:

Exception in thread "main" org.openqa.selenium.WebDriverException: document.selben.doFlexClick is not a function
commented by kushal
edited
^^can anybody help me with the above?
0 votes
answered by Bhartesh (2,630 points)

Try this code : 

  public String click(final String objectId, final String optionalButtonLabel) {    

    return call("doFlexClick", objectId, optionalButtonLabel);

  }

  public String click(final String objectId) {

     return click(objectId, "");

  }  

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

publicclass FlexWebDriver {  privatefinal WebDriver webDriver;privatefinal String flashObjectId;  public FlexWebDriver(final WebDriver webDriver, final String flashObjectId) {    this.webDriver = webDriver;

    this.flashObjectId = flashObjectId;

  }

  public String click(final String objectId, final String optionalButtonLabel) {    return call("doFlexClick", objectId, optionalButtonLabel);

  }

  public String click(final String objectId) {

     return click(objectId, "");

  }

  private String call(final String functionName, final String... args) {final Object result =

      ((JavascriptExecutor)webDriver).executeScript(

         makeJsFunction(functionName, args),

         new Object[0]);

     return result != null ? result.toString() : null;

  }

  private String makeJsFunction(final String functionName, final String... args) {

     final StringBuffer functionArgs = new StringBuffer();

    if (args.length > 0) {

      for (int i = 0; i < args.length; i++) {

        if (i > 0) {

          functionArgs.append(",");

      }

        functionArgs.append(String.format("'%1$s'", args[i]));

     }

    }

    return String.format(

      "return document.%1$s.%2$s(%3$s);",

      flashObjectId,

      functionName,

      functionArgs);

  }

}

 

Now the example of using clicking an element :

final FirefoxDriver driver = new FirefoxDriver();

final FlexWebDriver flexDriver = new FlexWebDriver(driver, “my-application”);

driver.get(“http://localhost:8080/application”);

 Assert.assertEquals(“true”, flexDriver.click(“aButton”));

Related Questions

Not a Member yet?

Answer Queue Login
131 Folks are online
0 members and 131 guest online