selenium对flex的支持
步骤:
1、DownloadandinstallSeleniumRC
2、DownloadSeleniumFlexAPI,andrebuildyourFlexapplicationwithSeleniumFlexAPI.swc(最主要的就是要重新编译你的swf文件,并加入相应的swc文件。)
地址:http://sourceforge.net/projects/seleniumflexapi/files/下载SeleniumFlex-API_0.2.5.zip,将里面的SeleniumFlexAPI.swc文件编译到你的flex应用中!
3、DownloadFlashSeleniumandaddtoyourtestproject
flash-selenium.jar加入到项目中
4、DownloadFlexUISeleniumandaddtoyourtestproject
地址:http://flex-ui-selenium.googlecode.com/files/flex-ui-selenium-0.1.1.jarflex-ui-selenium-0.1.1.jar加入到项目中
5、WriteandrunyourtestcasesagainstyourFlexapplications
测试代码如下:
publicclassFlexUISeleniumTest{
privatefinalstaticStringBASE_URL="http://www.geocities.com/";
privatefinalstaticStringPAGE="paulocaroli/flash/sum.html";
privateSeleniumselenium;
privateFlexUISeleniumflexUITester;
@Before
publicvoidsetUp()throwsException{
selenium=newDefaultSelenium("localhost",4444,"*iexplore",BASE_URL);
selenium.start();
selenium.open(PAGE);
flexUITester=newFlexUISelenium(selenium,"compareSumFlexObjId");
}
@After
publicvoidtearDown()throwsException{
selenium.stop();
}
@Test
publicvoidverifyFlexAppSumIsCorrect(){
flexUITester.type("2").at("arg1");
flexUITester.type("3").at("arg2");
flexUITester.click("submit");
assertEquals("5",flexUITester.readFrom("result"));
}
}
试了楼主贴的那一段代码,进展不是很顺利,花了些时间终于搞定了,所以来写一些注释,希望能够帮到其他人。
publicclassFlexUISeleniumTest{
privatefinalstaticStringBASE_URL="http://www.geocities.com/";
privatefinalstaticStringPAGE="paulocaroli/flash/sum.html";
privateSeleniumselenium;
privateFlexUISeleniumflexUITester;
//首先上边给的url已经过期,没有办法是用。解决办法就是用自己的url了,但是自己的工程一定要用sfapi.swc编译过才可以
@Before
publicvoidsetUp()throwsException{
selenium=newDefaultSelenium("localhost",4444,"*iexplore",BASE_URL);
//注意,这里如果用firefox会有一个bug,解决方法是用"*firefoxproxy"而不是"*firefox"
selenium.start();
selenium.open(PAGE);
flexUITester=newFlexUISelenium(selenium,"compareSumFlexObjId");
//这里compareSumFlexObjId要用你的flashObjectId,查你的HTML就可以找到
}
@After
publicvoidtearDown()throwsException{
selenium.stop();
}
@Test
publicvoidverifyFlexAppSumIsCorrect(){
flexUITester.type("2").at("arg1");
flexUITester.type("3").at("arg2");
flexUITester.click("submit");
//这里用的arg1,arg2还有submit是UIID或者name,如果你的工程正确编译了的话,鼠标悬停时会显示的
assertEquals("5",flexUITester.readFrom("result"));
}
}