步骤:
1、Download and install Selenium RC
2、Download Selenium Flex API, and rebuild your Flex application with SeleniumFlexAPI.swc (最主要的就是要重新编译你的swf文件,并加入相应的swc文件。)
地址: http://sourceforge.net/projects/seleniumflexapi/files/ 下载 SeleniumFlex-API_0.2.5.zip,将里面的SeleniumFlexAPI.swc文件编译到你的flex应用中!
3、Download FlashSelenium and add to your test project
flash-selenium.jar加入到项目中
4、Download FlexUISelenium and add to your test project
地址 :http://flex-ui-selenium.googlecode.com/files/flex-ui-selenium-0.1.1.jar flex-ui-selenium-0.1.1.jar加入到项目中
5、Write and run your test cases against your Flex applications
测试代码如下:
public class FlexUISeleniumTest {
private final static String BASE_URL = "http://www.geocities.com/";
private final static String PAGE = "paulocaroli/flash/sum.html";
private Selenium selenium;
private FlexUISelenium flexUITester;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",BASE_URL);
selenium.start();
selenium.open(PAGE);
flexUITester = new FlexUISelenium(selenium, "compareSumFlexObjId");
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
@Test
public void verifyFlexAppSumIsCorrect() {
flexUITester.type("2").at("arg1");
flexUITester.type("3").at("arg2");
flexUITester.click("submit");
assertEquals("5", flexUITester.readFrom("result"));
}
}
试了楼主贴的那一段代码,进展不是很顺利,花了些时间终于搞定了,所以来写一些注释,希望能够帮到其他人。
public class FlexUISeleniumTest {
private final static String BASE_URL = "http://www.geocities.com/";
private final static String PAGE = "paulocaroli/flash/sum.html";
private Selenium selenium;
private FlexUISelenium flexUITester;
//首先上边给的url已经过期,没有办法是用。解决办法就是用自己的url了,但是自己的工程一定要用 sfapi.swc 编译过才可以
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",BASE_URL);
//注意,这里如果用firefox会有一个bug,解决方法是用"*firefoxproxy" 而不是"*firefox"
selenium.start();
selenium.open(PAGE);
flexUITester = new FlexUISelenium(selenium, "compareSumFlexObjId");
//这里compareSumFlexObjId 要用你的flashObjectId,查你的HTML就可以找到
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
@Test
public void verifyFlexAppSumIsCorrect() {
flexUITester.type("2").at("arg1");
flexUITester.type("3").at("arg2");
flexUITester.click("submit");
//这里用的arg1,arg2还有submit是UI ID或者name,如果你的工程正确编译了的话,鼠标悬停时会显示的
assertEquals("5", flexUITester.readFrom("result"));
}
}
1、Download and install Selenium RC
2、Download Selenium Flex API, and rebuild your Flex application with SeleniumFlexAPI.swc (最主要的就是要重新编译你的swf文件,并加入相应的swc文件。)
地址: http://sourceforge.net/projects/seleniumflexapi/files/ 下载 SeleniumFlex-API_0.2.5.zip,将里面的SeleniumFlexAPI.swc文件编译到你的flex应用中!
3、Download FlashSelenium and add to your test project
flash-selenium.jar加入到项目中
4、Download FlexUISelenium and add to your test project
地址 :http://flex-ui-selenium.googlecode.com/files/flex-ui-selenium-0.1.1.jar flex-ui-selenium-0.1.1.jar加入到项目中
5、Write and run your test cases against your Flex applications
测试代码如下:
public class FlexUISeleniumTest {
private final static String BASE_URL = "http://www.geocities.com/";
private final static String PAGE = "paulocaroli/flash/sum.html";
private Selenium selenium;
private FlexUISelenium flexUITester;
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",BASE_URL);
selenium.start();
selenium.open(PAGE);
flexUITester = new FlexUISelenium(selenium, "compareSumFlexObjId");
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
@Test
public void verifyFlexAppSumIsCorrect() {
flexUITester.type("2").at("arg1");
flexUITester.type("3").at("arg2");
flexUITester.click("submit");
assertEquals("5", flexUITester.readFrom("result"));
}
}
试了楼主贴的那一段代码,进展不是很顺利,花了些时间终于搞定了,所以来写一些注释,希望能够帮到其他人。
public class FlexUISeleniumTest {
private final static String BASE_URL = "http://www.geocities.com/";
private final static String PAGE = "paulocaroli/flash/sum.html";
private Selenium selenium;
private FlexUISelenium flexUITester;
//首先上边给的url已经过期,没有办法是用。解决办法就是用自己的url了,但是自己的工程一定要用 sfapi.swc 编译过才可以
@Before
public void setUp() throws Exception {
selenium = new DefaultSelenium("localhost", 4444, "*iexplore",BASE_URL);
//注意,这里如果用firefox会有一个bug,解决方法是用"*firefoxproxy" 而不是"*firefox"
selenium.start();
selenium.open(PAGE);
flexUITester = new FlexUISelenium(selenium, "compareSumFlexObjId");
//这里compareSumFlexObjId 要用你的flashObjectId,查你的HTML就可以找到
}
@After
public void tearDown() throws Exception {
selenium.stop();
}
@Test
public void verifyFlexAppSumIsCorrect() {
flexUITester.type("2").at("arg1");
flexUITester.type("3").at("arg2");
flexUITester.click("submit");
//这里用的arg1,arg2还有submit是UI ID或者name,如果你的工程正确编译了的话,鼠标悬停时会显示的
assertEquals("5", flexUITester.readFrom("result"));
}
}