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

Popular Categories





How to Handle Dynamic flex components Using Selenium Webdriver?

+4 votes
520 views
asked in Software Testing by Niks
Can anyone Help me, How to Handle Flex components that are generated runtime through Action script using Selenium WebDriver?

2 Answers

+1 vote
answered by seleniumGuru Expert (4,570 points)

Hi Niks ,

You can see procedure here to automate flex in selenium and if these components like text box or button are dynamic so you can check the pattern how these components are generating may be their ids are also generating in a particular sequence  and use for loop to create dynamic ids or give some example code which flex grid you have to automate so that I can help you better. 

commented by Niks
Below is the code snipet which dynamically generates Menu. Please guide me how will i access third menu generated by this acttion script(and id of Menucontainer on flex screen is "menuholder")

private function createMenu(value:ArrayCollection):void {
           
            app.menuHolder.removeAllChildren();
           
            var groupVOs:ArrayCollection = MainScreenUtil.getGroupVOs(value);
           
            var groupingMenuRenderers:Array = [];        
            for each (var data:Object in groupVOs) {
                var groupingMenuRenderer:GroupingMenuRenderer = new GroupingMenuRenderer();
                groupingMenuRenderer.label = data["groupCode"];
                groupingMenuRenderer.labelField = "groupName";
                groupingMenuRenderer.data = data;
                groupingMenuRenderer.children = data["children"];
                groupingMenuRenderers.push(groupingMenuRenderer);   
            }
           
            var groupingMenu:GroupingMenu = new GroupingMenu();
            groupingMenu.addEventListener(GroupingMenuEvent.MENU_CLICK, onMenuClick);
            groupingMenu.groupingMenuRenderers = groupingMenuRenderers;
           
            app.menuHolder.addChild(groupingMenu);
            /**    var spacer : Spacer = new Spacer();
             spacer.percentHeight = 100;
             app.menuHolder.addChild(spacer);*/
           
            if (groupVOs.length > 0) {
                var vo : GroupVO= groupVOs.getItemAt(0) as GroupVO;           
                if (vo.children && vo.children.length > 0) {
                    selectTarget(vo.children[0]);
                } else {
                    selectTarget(vo);
                }
            }
commented by Niks
Please suggest me solution on this.
commented by Amir
The only way to interact with Flex applications using WebDriver is by using the JavaScriptExecutor to invoke JavaScript commands
0 votes
answered by Bhartesh (2,690 points)

Use 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

0 votes
0 answers 136 views
+2 votes
1 answer 100 views

Not a Member yet?

Ask to Folks Login

My Account
159 Folks are online
0 members and 159 guest online
Your feedback is highly appreciated