Selenium supports flex automation testing

Automated testing of flex programs by selenium
Because the company's project needs to import selenium to test flex programs, I have studied for a while and have achieved a little success, because during the research process, I found that selenium has relatively little application information on flex. Of course, I also learned here. something. So after the research, I will share with you what I have learned.
The following content is based on a certain understanding of selenium.
OK, here we go.
1) Of course, download Selenium RC, I use 0.9.2
http://seleniumhq.org/download/previous.html
2) You need to download the swc file and recompile and release your own flex project.
SeleniumFlexAPI.swc
http://sourceforge.net/projects/seleniumflexapi/

sfapi.swc:
http://code.google.com/p/sfapi/downloads/list
No matter how good the above is, in addition to the swc file, there are A user-extensions.js , wait a
minute, it is enough to know that there is such a file
3) Compile the flex project
3.1) I use eclipse, so I select the project in eclipse, select flex build pass
in the properties, and add that in the library Two swc files
3.2) Add the following to an additional parameter in flex compile (after -locale en_UA)
-include-libraries "../TBTFlex/lib/SeleniumFlexAPI.swc" "../TBTFlex/lib/sfapi.swc"

PS: Second, whether these two files are required in the third step, I am not very clear, anyway, two All are correct.

4) Next is the test project.
This must first read the relevant knowledge of selenium.
4.1) Build a project in Eclipse, add selenium-java-client-driver.jar
in selenium rc0.9.2
4.2) Download the jar package that supports flex and add
flash-selenium.jar to the project:
http://code .google.com/p/flash-selenium/downloads/detail?name=flash-selenium.jar&can=2&q=

flex-ui-selenium-0.1.1.jar
http://code.google.com/p/flex- ui-selenium/downloads/detail?name=flex-ui-selenium-0.1.1.jar&can=2&q=
4.3) add the junit package, this is required. . . I use the 3.8 that comes with eclipse
5) Next, introduce the test program
public void setUp() throws Exception {
String url = "http://172.16.173.100/";
selenium = new DefaultSelenium("localhost", 4444, "*iexplore", url);
selenium.start();
}

public void tearDown() throws Exception {
selenium.stop();
}
The above is also the knowledge of selenium, nothing more Well said public void test_BugMngRgst_init1

() throws Throwable {
//The login screen url of the flex application, this is jsp so you can use the selenium method
selenium.open("http://172.16.173.100/TBTLogin/");
//Enter the username
selenium.type("userid", "user");
//Enter the password
selenium.type("password", "pass");
//Press the login button
selenium.click("button1");
//This is because after login It is a flex program, so thread wait is used, otherwise the picture will not come out, and
Thread.sleep(3000) cannot be operated later ;
//Here is to get the flex picture object, Main is the id of the flash embedded in the jsp
flexUITester = new FlexUISelenium(selenium, "Main");
flashApp = new FlashSelenium(selenium, "Main");
//Here are a few examples of operating flex controls
//Read the contents of the text box with id username, this Controls such as square *****abel can also use
flexUITester.readFrom("username");
//Press the button whose id is registerButton, some pictures in this method can also be pressed
flexUITester.click("registButton");
//Yes The text whose id is gaiyo sets the value
flexUITester.type("zhanghuijie").at("gaiyo");
//There are also some methods, such as double-clicking, etc., which will not be described in detail.

Next is the user-extensions.js mentioned earlier , I only used the FlexUISelenium method at the beginning, and found that the support for flex was very limited. Later, when I looked at his source code, it was actually implemented by the call method of FlashSelenium. In addition, there are many methods in user-extensions.js, like It can also be used directly if it is not, and it turns out that it is possible, to give a few examples.
//This is the setting value of the drop-down box, aaaa is the id, 1 is to set the first value of the drop-down box
flashApp.call("doFlexSelectIndex","aaaa" ,"1");

flashApp.call("getFlexDataGridRowCount", "bbbb");
There are many methods in user-extensions.js, and I haven't tested them one by one. I believe that although I can't operate all flex controls, many of them can still be operated.

I hope you can discuss with each other, but I still don't understand a lot.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326793204&siteId=291194637