Selenium automated testing of flex programs

Source: Internet
Author: User

Because the company's project needs to be imported into selenium to test the flex program, I've been studying for a while, because in the course of the study, I found that selenium used less data on flex, and certainly learned something about it here. So after the study, I learned to take to discuss with you.

The following 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 your flex project to publish.
Seleniumflexapi.swc
http://sourceforge.net/projects/seleniumflexapi/

SFAPI.SWC:
Http://code.google.com/p/sfapi/downloads/list
The above this next good, in addition to the SWC file, there is a user-extensions.js
Just wait and say, first you know there's a file on it.
3) Build Flex Project
3.1) I was using eclipse, so I chose the project in Eclipse, the Flex build Pass is selected in the properties
Add the two SWC files to the library
3.2) in the flex compile inside an append parameter (-locale en_ua behind) append the following things
-include-libraries ". /TBTFLEX/LIB/SELENIUMFLEXAPI.SWC "". /TBTFLEX/LIB/SFAPI.SWC "

PS: Second, three steps these two files whether all need, I am not too clear, anyway two are plus right.

4) Next is the test project
This must first look at the selenium of the relevant knowledge.
4.1) Eclipse built a project to join Selenium-java-client-driver.jar
Selenium rc0.9.2.
4.2) Download the jar package for flex support and add it to the project
Flash-selenium.jar:
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 JUnit package, this is required ... I'm using 3.8 of Eclipse's own.
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 selenium knowledge, there is nothing to say

public void Test_bugmngrgst_init1 () throws Throwable {
The login screen URL for the Flex app, which is a JSP so you can use the Selenium method
Selenium.open ("http://172.16.173.100/TBTLogin/");
Enter user name
Selenium.type ("userid", "User");
Enter password
Selenium.type ("Password", "pass");
Press the login button
Selenium.click ("Button1");
This is because after landing is the flex program, so with the thread wait, otherwise the screen does not come out, the back can not be manipulated
Thread.Sleep (3000);
Here is the Flex screen 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 how flex controls are manipulated
Reads the contents of the text box with the ID username, and this method can also be used for a label control
Flexuitester.readfrom ("username");
Press the button with ID Registbutton, this method some pictures can also press
Flexuitester.click ("Registbutton");
Set the value for the text with ID Gaiyo
Flexuitester.type ("Zhanghuijie"). at ("Gaiyo");
There are some methods, like double-click and so on not detailed said

Next is said User-extensions.js, at the beginning only with the Flexuiselenium method, found that the flex support is very limited, then see his source code, in fact, is also used Flashselenium call method to achieve, plus USER-EXTENSIONS.J s inside see there are many ways, like is not also can be directly used, the results proved to be possible, give a few examples.
This is the set value of the drop-down box, AAAA is id,1 is the first value of the Set dropdown box
Flashapp.call ("Doflexselectindex", "AAAA", "1");
This is the number of data bars in the DataGrid, BBBB is the ID
Flashapp.call ("Getflexdatagridrowcount", "bbbb");
There are many methods in user-extensions.js, I do not have one by one test, I believe that although the flex control can not operate, but a lot of it is still operational.

I hope that we can explore each other, in fact, I still have a lot of do not understand.

--------------------------------Reviews--------------------------------------

Today add a newly-developed command to the DataGrid operation,
Get the contents of a cell in the DataGrid
Flashapp.call ("Getflexdatagridcell", "aaa,1,5");

AAA is the ID of the DataGrid
1 is OK
5 is the column

/tr>
 
complements tab operation today

JUnit:
Flashapp.call ("Doflexclick", "TabID", "Tablabel");

Flex:
<mx:tabnavigator id= "TabID" ... >    

     <mx:canvas label= "Tablabel" ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.