Forum Discussion

Leahy's avatar
Leahy
Contributor
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 undefined.

  • Hi,

     

    '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.

     

  •  can we get a copy of the entire script routine that calls on state.SystemMenu.Count 

    you are right that the error is misleading as the variable state seems to clearly be defined 

    • Leahy's avatar
      Leahy
      Contributor

      function Test1()
      {
      var i = 0;
      var j = 0;
      var p = Sys.Process("wfica32");
      state = Aliases.wfica32.dcsc03_Manage_Daily_Schedules_BUS_JUN17_Remote;


      Aliases.wfica32.hdo01_HASTDEV2016_hastdev2016_JUN17_BUS_25_06_2017_Remote.DblClick(441, 256);
      state = Aliases.wfica32.dcsc03_Manage_Daily_Schedules_BUS_JUN17_Remote;

      while (1)
      {
      w = p.Waitwindow("*","dcsc03 - Man*",0,1000);

      if (i > 100)
      {

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

      i = 0;
      j++;
      }
      i++;
      if (j > 10) break;
      }
      }

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        '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.