FlexUnit 4 Testing Services In Flash Player Issue


We’ve created a number of FlexUnit 4 (FU4) tests for our current, large project and the suite of tests that seems to be of the most importance to both us and our client is the one that tests the services. Our client’s back-end services are simple JSPs that return XML payloads for a number of CRUD operations on various objects in the system, so we’d like to test sending good required data as well as bad required data to our delegate before hitting the service directly.

The issue we ran into was quite frustrating and it took me some time to figure it out — I actually had to explain the system of tests to my partner before it dawned on me what was going wrong. In order to actually hit the services and get data back, you need to be logged into our client’s system…except this isn’t done through a Flex login, but rather via the larger application’s HTML login in which our smaller app lives (SSO)…once you’re logged in, a cookie is sent back and forth between the client and server…such is the security design of our client’s application framework and there wasn’t any wiggle room to change this.

SWF Browser Association

Change SWF to Open With Browser

Now think about FU4 and how it actually runs the tests (when using Ant and not building and running with FlexBuilder)…it simply opens up a TestRunner.swf in the Flash Player to execute it’s tests…this means no browser wrapper for our SWF and thus no access to cookies…and ultimately no working services in my tests…grrrr.

So here’s a simple solution (on Mac)…open up Finder and locate your TestRunner.swf, right-click on it and select “Get Info”. Find the section “Open with” and change the application to your browser (I use FireFox), but don’t click the button change for all, as we just want to change this for this file and this file only. Voila! Now your TestRunner.swf will run in thr browser when your Ant buld runs and you will have access t cookies (assuming you’ve already logged into the system you need access to in the same browser session).

Post to Twitter Tweet This Post

, , , , , , ,

  1. #1 by Christian - December 10th, 2009 at 16:25

    Hey,

    We had the exact same problem with a flexunit4 test, and it took a while before figuring out that cookies are the culprit.
    The weird thing is though, that this test works perfectly on windows, while it fails on OS X & Ubuntu.
    It looks like the windows flashplayer provides cookie support while the others don’t…. weird.

    Although your workaround works when opening the swf, it still doesn’t work when using flexmojos, because that loads flashplayer directly…

    any thoughts?

  2. #2 by Christian - December 11th, 2009 at 05:28

    We have the same problem over here (on OS X/linux)
    The strange thing is that a flash player on windows doesn’t give any problems. It looks like the windows flashplayer has cookie support somehow.

    We’re looking for a solution on osx/linux because of flexmojos integration.

  3. #3 by Brian LeGros - December 11th, 2009 at 18:44

    For what it’s worth, browser support via the FlexUnit4 Ant task rather than using the SA player is the next big item I’m tackling in the coming weeks. The solution we’re going to be using it very similar to what you’re describing with some exceptions for Linux. When the support is done we’ll have support for the SA player, ADL, and the browser as it relates to CI. For updates on our progress, keep an eye on our GitHub master branch for FlexUnit4 @ http://github.com/flexunit/flexunit.

  4. #4 by hDave - October 26th, 2010 at 00:24

    Any further progress made on this? Am looking to run FlexUnit4 integration tests within a browser via Maven,

  5. #5 by Nikos - December 23rd, 2010 at 09:00

    any chance you could share the code you use to send and receive cookies in your tests?

(will not be published)