15 Replies Latest reply: Mar 31, 2012 11:30 PM by flashquartermaster RSS

    ActionScript Project

    ronzoni17

      I have an ActionScript Project and I have been running unit tests using the FlexUnit 4 integration in Flash Builder 4 Beta 2. These have been working great until I try to use UIImpersonator, which uses Flex classes and fails in my pure ActionScript project. (UIImpersonator works fine with a Flex Project.)

       

      Since Flash Builder is for both Flex and ActionScript projects, I figured I would be able to use FlexUnit to equal extents. Is there an ActionScript project equivalent to UIImpersonator, or just a way to access the Stage?

        • 1. Re: ActionScript Project
          Michael Labriola Community Member

          Right now UIImpersonator has dependencies on UIComponent which is the reason it is only compiled into Flex projects. It is a goal to make this feature suitable for ActionScript projects. However, there will always be somethings that the Flex version can do that the ASOnly version cannot. For instance, binding and container based ideas.

           

          We will add a feature request to Jira for this so you can track out progress,

          Mike

          • 2. Re: ActionScript Project
            ronzoni17 Community Member

            Ok, thanks Michael.

             

            Supplying access to the stage would allow my AS application to run its natural course. It's all I would personally need to do testing. Without it, my application will not run at all.

             

            If there is any workaround you can think of to access the stage, please let me know.

            • 3. Re: ActionScript Project
              Michael Labriola Community Member

              http://www.uza.lt/codex/as3-global-object/

              Actually scratch that suggestion for the moment.

               

              I will work on a work around for you

               

              Mike

              • 4. Re: ActionScript Project
                ronzoni17 Community Member

                That would be fantastic, Mike. Thanks!

                • 5. Re: ActionScript Project
                  ronzoni17 Community Member

                  Hi Michael,

                   

                  Just following up here. Is there another FlexUnit Beta in the works? Stage access is critical to my testing.

                   

                  Thanks!!!!

                  • 6. Re: ActionScript Project
                    Michael Labriola Community Member

                    There is a version that will be available shortly with a proposed fix.

                     

                    Will post as soon as it is ready, and will appreciate if you can jump on testing it quickly when you can.

                     

                    Thanks,

                    Mike

                    • 7. Re: ActionScript Project
                      ronzoni17 Community Member

                      Great! Yes, my team and I will begin testing immediately. Thanks Michael!

                      • 8. Re: ActionScript Project
                        ronzoni17 Community Member

                        Hey Michael,

                         

                        I am able to compile now with the UIImpersonator in my ActionScript-only project, and I can add display objects to the UIImpersonator, but the DisplayObjectContainer that I am adding them to has a stage property with a value of null.

                         

                        This DisplayObjectContainer is an instance of org.fluint.uiImpersonation.actionScript.ActionScriptVisualTestEnvironment, and it has a protected stage property that I can't access. This stage property is passed to ActionScriptVisualTestEnvironment in the constructor, so I can't subclass it.

                         

                        Maybe I've over-investigated, is there a simple way to access the stage? Shouldn't the UIImpersonator be on the stage when I call addChild()?

                         

                        Thanks,

                        Gianni

                        • 9. Re: ActionScript Project
                          Michael Labriola Community Member

                          Gianni,

                           

                          Sorry, I haven't had a chance to document this yet, but, as you have seen, you can now call those UIImpersonator methods. There is one more requirement though to make this all work.

                           

                          Before you run your tests in an AS only project, you need to create the VisualEnvironment and pass it a reference to the stage. Here is a quick example from my testing:

                           

                                      var environmentBuilder:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance( this );

                                      var spt:Sprite = new Sprite();

                                      trace( UIImpersonator.numChildren );

                                      UIImpersonator.addChild( spt );

                                      trace( UIImpersonator.numChildren );

                           

                           

                                      var core:FlexUnitCore = new FlexUnitCore();

                                      core.addListener( new TraceListener() );

                                      core.run( FlexUnitIn360 );

                           

                          The *this* reference passed into the getInstance() method is the stage reference.  This interface could change slightly in the future, but this is the best solution I have been able to find so far.

                           

                          Mike

                          • 10. Re: ActionScript Project
                            ronzoni17 Community Member

                            Thanks Mike.

                             

                            I'm confused on where would I execute this code:

                             

                            var environmentBuilder:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance( this );

                             

                            Currently, I only have the Unit Test classes in my TestSuite, and I run the Unit Tests with Flash Builder 4.

                             

                            public class TestStuff
                            {
                                 public function TestStuff()
                                 {     
                                 }
                                      
                                 [Test]
                                 public function test():void{
                                      // obviously passing "this" isn't going to help here...
                                      var environmentBuilder:IVisualEnvironmentBuilder = VisualTestEnvironmentBuilder.getInstance( this );
                                 }
                            }
                            

                             

                            Thanks,

                            Gianni

                            • 11. Re: ActionScript Project
                              Michael Labriola Community Member

                              Gianni,

                               

                              It needs to be called before the core.run() is called like in my example.

                               

                              How are you running the tests, flash builder or another ide?

                               

                              Mike

                              • 12. Re: ActionScript Project
                                ronzoni17 Community Member

                                Flash Builder, so I'm not calling core.run() explicitly, the file that calls it is being generated by the IDE, I'm guessing.

                                • 13. Re: ActionScript Project
                                  Michael Labriola Community Member

                                  Fair enough. I am still working with Adobe to see if they can call this automatically, however, you can actually use it without Adobe's auto-generated code. Will put together a sample for you.

                                  • 14. Re: ActionScript Project
                                    pup500 Community Member

                                    I found this BDD project page, which includes a stage access example:

                                    Cuke4AS3 https://github.com/flashquartermaster/Cuke4AS3/

                                     

                                    [EDIT]

                                    After much research and complication, I ended up using a Singleton that provides a stage reference that was passed in from a `creationComplete` handler in my TestRunner.

                                     

                                    =======TestRunner.mxml==========================================

                                     

                                    <?xml version="1.0" encoding="utf-8"?>

                                    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

                                        creationComplete="onCreationComplete()"

                                        xmlns:flexUnitUIRunner="http://www.adobe.com/2009/flexUnitUIRunner"

                                        styleName="flexUnitApplication"

                                        layout="absolute" height="800" width="1000">

                                        <mx:Script>

                                            <![CDATA[

                                                import org.flexunit.runner.FlexUnitCore;

                                                private var core:FlexUnitCore;

                                                public function onCreationComplete():void {

                                                    core = new FlexUnitCore();

                                                    core.addListener( new TraceListener() );

                                                    core.addListener( new UIListener( uiListener ));

                                                    new StageLocator(systemManager.stage);

                                                    core.run(MyTestSuite);

                                                }

                                            ]]>

                                        </mx:Script>

                                        <mx:Style>

                                            Application {

                                                   backgroundColor: #3872b2;

                                                   backgroundGradientColors: #3872b2, #0c1a3d;

                                                   backgroundGradientAlphas: 1, 1;

                                                   themeColor: #ffffff;

                                                   color: #444444;

                                                   fontFamily: "Myriad Pro Semibold";

                                                   fontSize: 12;

                                                }

                                        </mx:Style>

                                        <flexUnitUIRunner:TestRunnerBase id="uiListener" width="100%" height="100%" />

                                    </mx:Application>

                                     

                                    =======StageLocator.as==========================================

                                     

                                    package {

                                    import flash.display.Stage;

                                    public class StageLocator {

                                        public static var instance:StageLocator;

                                        public static var stage:Stage;

                                        public function StageLocator ($stage:Stage) {

                                            instance = this;

                                            stage = $stage;

                                        }

                                    }

                                    }

                                    • 15. Re: ActionScript Project
                                      flashquartermaster

                                      There is a gist here: https://gist.github.com/1094408 that explains how to access the stage from a pure ActionScript project.