+10 votes
37.8k views
in Software Testing by (1.6k points)
retagged by
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!
closed

1 Answer

+8 votes
by Expert (4.6k points)
selected by
 
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.

0
by Expert (4.6k points)
edited by
3.you can make a java file with this code.
    package com.kdf;

import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class FlexWebDriver {    
    private final WebDriver webDriver;
    private final String flashObjectId;    
    public FlexWebDriver(final WebDriver webDriver, final String flashObjectId) {       
        this.webDriver = webDriver;
        this.flashObjectId = flashObjectId;
    }

   
     public String doFlexClickMenuBarUIComponent(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexClickMenuBarUIComponent", objectId, optionalButtonLabel);
   }

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

    public String click(final String objectId) {
         return click(objectId, "");
    }
    public String ClickDataGridItem(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexClickDataGridItem", objectId, optionalButtonLabel);
   }

    public String ClickDataGridItem(final String objectId) {
         return click(objectId, "");
    }
    
    public String FlexClickDataGridUIComponent(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexClickDataGridUIComponent", objectId, optionalButtonLabel);
   }

    public String FlexClickDataGridUIComponent(final String objectId) {
         return FlexClickDataGridUIComponent(objectId, "");
    }
    
    public String FlexSelectComboByLabel(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexSelectComboByLabel", objectId, optionalButtonLabel);
   }

    public String doFlexSelectComboByLabel(final String objectId) {
         return click(objectId, "");
    }
    public String FlexSelect(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexSelect", objectId, optionalButtonLabel);
   }

    public String FlexSelect(final String objectId) {
         return FlexSelect(objectId, "");
    }
    public String FlexRefreshIDToolTips(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexRefreshIDToolTips", objectId, optionalButtonLabel);
   }

    public String FlexRefreshIDToolTips(final String objectId) {
         return FlexRefreshIDToolTips(objectId, "");
    }
    public String FlexDoubleClick(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexDoubleClick", objectId, optionalButtonLabel);
   }

    public String FlexDoubleClick(final String objectId) {
         return FlexDoubleClick(objectId, "");
    }
    public String FlexSetFocus(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexSetFocus", objectId, optionalButtonLabel);
   }

    public String FlexSetFocus(final String objectId) {
         return FlexSetFocus(objectId, "");
    }
    public String FlexMouseMove(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexMouseMove", objectId, optionalButtonLabel);
   }

    public String FlexMouseMove(final String objectId) {
         return FlexMouseMove(objectId, "");
    }
    public String FlexType(final String objectId, final String optionalButtonLabel) {       
        return call("doFlexType", objectId, optionalButtonLabel);
   }

    public String FlexType(final String objectId) {
         return FlexType(objectId, "");
    }
    
    public String getFlexDataFieldLabelForGridRow(
            String dataGridId, String field, int row) {
        return call("getFlexDataGridFieldLabelForGridRow", dataGridId, field, Integer.toString(row));
    }
    public int getFlexDataGridRowCount(String dataGridId ) {
        return Integer.parseInt(call("getFlexDataGridRowCount", dataGridId));
    }
    public int getSelectionIndex(String selectionFieldId) {
        return Integer.parseInt(call("getFlexSelectionIndex", selectionFieldId, ""));
    }

//... Omitted for clarity ...

    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 you can use these functions in your selenium file.
For More functions download user extension
I hope you got the point.
0
by (1.6k points)
Thanks dear now i am able to click on flex .thanks a lot. :)
0
by Expert (5.9k points)
i tried many tools like flex monkey , flex pilot some how i was not able to do click on flex element , when i used this SFAPI .swc  file by following these steps and i made a java file with these functions above in point three and i just called this function
public String click(final String objectId) {
return click(objectId, "");
}
and given id of a flex button then the magic begains its clicked the element , i was very happy ... good job @selenium guru thanks for such a good explanation.
0
by (100 points)
edited by
Thank you this is helpful.
I need to know more/ in detail. please can u help me on the same.
our application is complied/build with SeleniumFlexAPI.swc and followed steps as u mentioned setting up lib path in flex compiler

1. How to use these functions....?
2. How to get ObjectID's and function names etc i am totally confused. please let me know. as i tried doing F12 not able to get.
3.  Do i need to use mxml / .as files, if yes how to configure those files in selenium webdriver please let me know.
0
by Expert (5.9k points)
Hi #Uma for ObjectID's you need to see your flex code or ask developers for ObjectID's where you have to perform actions.

There is no need to use mxml or .as files.

For point 1. :

You just have to create a java file copy all code(Modify as per the need like package name etc.) from point 3 then save it, Now from where you are using selenium function, Create a object of this file like:

final FlexWebDriver flexDriver = new FlexWebDriver(driver, strFlexObjectId);
       
flexDriver.click(strElementid);

here strFlexObjectId = flex application id(its a unique id of flex application id ,you can ask developers for this)

strElementid= its a element id where you have to perform action(Like if you want to click on a button you have to put that button id here)

I hope you got it, if any concern so let me know.
0
by
a.  you need to put this file in your flex application.

    b. you need to add lib path in flex compiler like this and comile the code  

                                                       -include-libraries "libs\SeleniumFlexAPI.swc"
Could you please elaborate more on the above
0
by Expert (4.6k points)
1. you have to download selenium flex api .

After downloading this selenium flex api, There would be a file SeleniumFlexAPI.swc in the folder find it and copy this file.

2. you will get a SeleniumFlexAPI.swc file here.

    a.  you need to put this file in your flex application.

         Now open the flex project in eclips or any other software then paste that SeleniumFlexAPI.swc file in the lib folder of project.


    b. you need to add lib path in flex compiler like this and comile the code  


After putting that SeleniumFlexAPI.swc file in lib clean the project and compile the project again with adding this path given below in flex compiler.

                                                       -include-libraries "libs\SeleniumFlexAPI.swc"

Then try, I hope you got the point.
0
by
where should we add this path '-include-libraries "libs\SeleniumFlexAPI.swc"' in eclipse?
0
by (2.9k points)
Hi disha, this path needs to be added in flex compiler if the flex application that you want to automate is developed flex builder.

For flex compiler : - Right click on the project and select properties and type flex compiler.

Now in the place of additional parameter put this path then compile the project and deploy it. Now SeleniumFlexAPI is included with your flex code and when you will call any function of it from client site it will work. In case any problem ,let me know!
0
by
Hi,
where can i find the unique id of flex application id in my flex project? i m using flex builder 3
0
by (2.9k points)
Disha see I am showing a example here :  This is a flex code

<Box backgroundColor="haloSilver" backgroundAlpha="0.4">
        <Graphic>
            <TextBox id="textBox"
                    text="The quick brown fox jumps over the lazy dog."
                    trackingLeft="{slider1.value}"
                    trackingRight="{slider2.value}"
                    textAlign="justify"
                    textJustify="interWord"
                    fontSize="16"
                    width="400" />
        </Graphic>
    </Box>

Here you can see TextBox has a unique id that is  id="textBox" you can use this id. same as for all elements like button etc.
0
by
Thanks alot for ur reply.
I have followed all 3 steps.

below is my flex code named TestProject.

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2008/03/09/calling-javascript-functions-from-your-flex-applications-using-the-externalinterface-api/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white">

    <mx:Script>
        <![CDATA[
            private function callJavaScript():void {
                ExternalInterface.call("sayHelloWorld");
            }
        ]]>
    </mx:Script>

    <mx:Button id = "mybutton" label="Say 'Hello World'"
            click="callJavaScript();" />

</mx:Application>

and here is my selenium code:




import java.util.concurrent.TimeUnit;

import org.openqa.selenium.*;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

public class seleniumwebdriver{
public static void main(String[] args) throws InterruptedException {
    System.setProperty("webdriver.ie.driver", "C:\\Users\\Downloads\\IEDriverServer_x64_2.39.0\\IEDriverServer.exe");
    InternetExplorerDriver driver;
    driver = new InternetExplorerDriver();
 
    
    try {
        driver.get("C:/Users/Documents/Flex Builder 3/TestProject/bin-debug/TestProject.swf");
        System.out.println("Webpage loaded.");
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        Thread.sleep(10000);
        System.out.println(driver.getPageSource());
        driver.manage().timeouts().setScriptTimeout(30, TimeUnit.SECONDS);

    final FlexWebDriver flexDriver = new FlexWebDriver(driver,"TestProject");
        
    flexDriver.click("mybutton");
       
        
    } catch (Exception e) {
        e.printStackTrace();
    }
    finally{
        Thread.sleep(15000);
    }
  }
}

I want to know how do i hit this button(with id = 'mybutton') of the flex screen using selenium.
Here,Selenium is able to launch the flex screen but it is not able to hit the button.
0
by (2.9k points)
I have two questions :
1. have you added the user extension function which explained above main answer in 3rd step?

2. what actually problem or exception is coming when you running code your code seems fine.

I was trying to message you my contact details so that can explain you better ,I think you are not a member here...anyways let me know these 2 points.
0
by
it wud be great if u can message me ur contact details.
[email protected]
0
by
Can someone let me know SFAPI.SWC file supports Flex 4.5 SDK application? I am trying to use this swc for my application but evertime it is throwing below error message.

Could you please suggest JavaScript error (WARNING: The server did not provide any stacktrace information)

Command duration or timeout: 147 milliseconds

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated