Forum Discussion

kalldrexx's avatar
kalldrexx
Contributor
14 years ago

TC7's WaitAliasChild is not using the supplied WaitTime parameter

It seems like the WaitAliasChild() function does not work correctly as described in the TC7 docs.  For example, I want to check if my WinRDE.fmEditCheck aliased window exists.  If I just try to access WinRDE.fmEditCheck when it doesn't exist, TC sits there for 10-20 seconds trying to find it or access it, so I decided to try and use WaitAliasChild to fix that (if it doesn't exist, it's not going to exist).  So in my code I have the following code (note: all code is done in C# using the C# TC libraries):





var rde = Aliases["WinRDE"];

var win;

win = rde[wac]("fmEditCheck", 5);

if (win["Exists"])

{

    ..... code ....

}





With this code, if fmEditCheck exists, everything is fine.  If the fmEditCheck form does not exist, the code is *supposed* to wait for 5 milliseconds and then move on to the IF statement if it's not found, and the win object should be a stub object.  Unfortunately, what happens is if the fmEditCheck form does not exist TC freezes for 10-20 seconds, and in the TC status bubble in the upper right hand of the screen it says "Waiting for the fmEditCheck object".



As a side note, setting the WaitTime parameter 0 does seem to work as intended, but it seems to miss the fmEditCheck form coming into existance.  Also everything works fine when the fmEditCheck window does exist

7 Replies

  • Hi Matthew,



    Which exactly version of TestComplete 7 do you have (Help | About...)? If you do not have the latest version which is 7.52, please install it and let me know if you see this behavior in this case as well.



    If the issue occurs with this version of TestComplete, please request a trial version of TestComplete 8.10 and check whether the problem occurs with it.



    If this behavior can be reproduced even with this version of TestComplete, please check whether it occurs with another application. For example, you can check this with Notepad and its Font dialog.



    Please let me know your results.
  • I am using TC 7.52.678.7



    This is easily reproducible using notepad.  I created a new project, mapped the main notepad window and the font dialog.  I then ran the following code:






    function Main()

    {

      try

      {

        var win = Aliases["Sys"]["notepad"]["WaitAliasChild"]("dlgFont", 5);

      }

      catch(exception)

      {

        Log["Error"]("Exception", exception["description"]);

      }

    }




    Upon running this while the font dialog does not exist causes TC to keep looking for it for about 10-15 seconds

  • Hi Matthew,





    Thank you for the sample.

    The problem exists in TestComplete 7.52 indeed. However, it is fixed in TestComplete 8.0.

  • So we have to pay so we don't encounter bugs?  No thanks.  I have already submitted bug reports a year ago for things that were never fixed in the 7 branch (for stupid things too, such as Test Complete not being able to handle if ( new var(whatever) == null) without crashing) so we aren't exactly ecstatic about TC as a whole, and convincing management to allow us to budget the high cost to upgrade our 4 licenses just for bug fixes isn't worth my effort.

  • Hi Matthew,





    Sorry for the inconvenience you are experiencing because of these issues. Unfortunately, we do not release any patches or fixes for old versions of the tool.





    Could you please contact me directly via the Contact Support form? I will try to suggest you a possible way to resolve this situation.
  • Thanks for the reply.



    I have a hack workaround working so far, which involves using the real object's WaitVCLObject when I want to see if something exists or not, since WaitVCLObject and WaitWindow actually works correctly.  Unfortunately, this means I am asking if a VCLObject exists and then instantiating an alias, which looks kind of confusing.  



    The proper workaround I have in mind, which I am going to try to code up this afternoon, is creating a c# method that will take in a VCLObject, call WaitVCLObject to determine if the object exists within the timeout.  If it does then return the alias based off the object's MappedName.  The only issue that I foresee is I'm not sure if it's possible to create an Alias object from the full mapped name with the TC API (e.g. translate the MappedName property of "Aliases.WinRDE.fmMain" into a C# Aliases["WinRDE"]["fmMain"] object).  
  • If anyone is interested, here is the code I worked up that (so far) seems to work pretty well.






            /// <summary>

            /// Checks if a child object exists and retrieves that child's alias mapping

            /// </summary>

            /// <param name="parent">Parent object</param>

            /// <param name="childName">Name of the child VCLObject</param>

            /// <param name="timeout">Maximum amount of time (in milliseconds) to wait for the child to exist</param>

            /// <returns>Alias object for the VCLObject</returns>

            public static var GetVCLChildAsAlias(var parent, string childName, int timeout)

            {

                // Make sure the parent exists

                if (parent == new var(null) || !parent["Exists"])

                    return new var();





                var child = parent["WaitVCLObject"](childName, timeout);





                // Make sure the child exists

                if (!child["Exists"])

                    return new var();





                // Get the mapped name and make sure it's a valid alias

                string[] mappedName = ((string)child["MappedName"]).ToString().Split('.');

                if (mappedName.Length < 2 || mappedName[0] != "Aliases")

                    return new var();





                // Loop through all the alias names and create the real alias object

                var aliasedChild = Aliases;

                for (int x = 1; x < mappedName.Length; x++)

                {

                    // Build the alias object.  This assumes that all parent aliases actually exist

                    //   if the aliased parents do not exist, this will cause TC to stall waiting for the object

                    aliasedChild = aliasedChild[mappedName];

                }





                return aliasedChild;

            }