To Support Cookies, Using Flexmojos with Firefox to Run Unittests for CI Server(Hudson) in Headless Environment
February 20th, 2010Flexmojos is a convenient tool used to compile and test flex applications. However, when running unittests in headless linux with Hudson, I met a problem caused by cookies. The server side needs cookies to make sure requests are valid. I googled a lot and find such a solution finally.
- you are required to install xvfb according the instructions in this article.
- you must have firefox 3.x.x installed.
- navigate to “about:config” in firefox and set “dom.allow_scripts_to_close_windows” to “true”;
- register executions for flexmojos-maven-plugin like this:
<executions> <execution> <id>default-test-compile</id> <configuration> <useNetwork>false</useNetwork> </configuration> </execution> <execution> <id>default-test-run</id> <configuration> <flashPlayerCommand>firefox</flashPlayerCommand> </configuration> </execution> </executions>
- download proper SWC according to the flexmojos version here. For example, I am using flexmojos 3.5.0, so I choose to download flexmojos-unittest-support-3.5.0.swc.
- checkout source code of flex-unittests-support with svn here.
- create a flex library project with flex(flash) builder called “flexmojos-unittest-support”, a sample project you can find here.
flexmojos-unittest-support.rar (40.6 KiB, 106 hits) - modify function exitFP defined in class org.sonatype.flexmojos.unitestingsupport.ControlSocket:
private function exitFP( event:* ):void { //Exiting trace("Exiting"); if(ExternalInterface.available) { var functionStr:String = "function()" + "{" + "window.opener=null;" + "window.open('','_self');" + "window.close();" + "}"; ExternalInterface.call(functionStr); } else { fscommand("quit"); } } - add flexmojos-unittests-support-x.x.x.swc as a library of this project.
- compile and build flexmojos-unittest-support.swc.
- install flexmojos-unittest-support.swc into maven repository according to the version of the flexmojos being used. For example, I am using flexmojos-3.5.0, so I run the command below under the bin directory of the flex library project:
mvn install:install-file -DgroupId=org.sonatype.flexmojos -DartifactId=flexmojos-unittest-support -Dversion=3.5.0 -Dpackaging=swc -Dfile=flexmojos-unittest-support.swc -DcreateChecksum=true
- now, you can run unittests with hudson supporting cookies.
NOTE: The javascript code used to close the browser can work with firefox, can not work with IE8. I do not test the other browsers.

February 21st, 2010 at 2:30 am
Nice,
I never thought that was even possible!
This could be used on a plugin that runs on integration-test phase…. I did like what you did, what do you think in making it part of flexmojos?
VELO
February 21st, 2010 at 10:39 pm
I think you just need to update your ControlSocket class to support different browsers. However, maybe Firefox support is enough :D. Javascript compatibility is quite annoying.
Then add a note here to indicate how to solve the cookies problem. The users merely set flashPlayerCommand to “Firefox” and it would work well.
Edison
March 14th, 2010 at 12:40 am
I read a article under the same title some time ago, but this articles quality is much, much better. How you do this?
March 15th, 2010 at 9:19 pm
Seems your comment is treated as spam by Akismet. What do you mean about “quality”? format? content? or something else?
April 13th, 2010 at 9:44 pm
Thanks for the tutorial, works well on Linux. Does anyone has this working on Mac osx? The problem we encounter on Mac may be due to Firefox not shutting down after the (last) window is closed.
April 14th, 2010 at 12:05 am
Sorry, I have no Mac to test. I think you can google for some information. If you can get an idea, please send me a note. Thank you :D.