Forum Discussion

Leahy's avatar
4 years ago

Run time error with state.SystemMenu.Count

Hello, I was wondering if I am doing something wrong here, I am totally confused.  The watch list shows this variable with a value, see attached pics.  But I am getting an error that says it is unde...
  • AlexKaras's avatar
    4 years ago



    'Cannot read property of undefined' in JScript is a clear indication that the parent object of the property does not exist.

    In your case, this means that the SystemMenu object does not exist and thus .Count property cannot be evaluated.


    Several more notes:

    a) Your code seems to mix Aliases and Sys objects to reference the same objects. Generally speaking this is not the best approach;

    b) As it is documented, Aliases object uses late binding which is resolved when the variable that keeps the reference to the Aliased object is used for the first time and tries to cache obtained object reference;

    c) If the (Aliased) object, the reference to which is stored in the variable is recreated, this does not refresh the reference but invalidates it.


    With the above in mind:

    > state = Aliases.wfica32.dcsc03_Manage_Daily_Schedules_BUS_JUN17_Remote;

    > ...

    > Log.Message("Menu Count = "+ state.SystemMenu.Count);

    Possible scenario (depending on your tested application's implementation):

    TestComplete tries to resolve the reference to the dcsc03_Manage_Daily_Schedules_BUS_JUN17_Remote object and store it to the state variable. If the sought for dcsc03_Manage_Daily_Schedules_BUS_JUN17_Remote object does not exist at this moment of time, reference to empty object is stored to the state variable. Even if the object appears some time later, this will not update the reference in the state variable and the variable will still keep the null reference.

    The attempt to get a reference to the child SystemMenu object and its Count property in the situation like this will result in the 'Cannot read property of undefined' error that you've got.