cancel
Showing results for 
Search instead for 
Did you mean: 

Run time error with state.SystemMenu.Count

SOLVED
Contributor

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Community Hero

Re: Run time error with state.SystemMenu.Count

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.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

3 REPLIES 3
Staff

Re: Run time error with state.SystemMenu.Count

 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 

Best,
Justin Kim
Contributor

Re: Run time error with state.SystemMenu.Count

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;
}
}

Community Hero

Re: Run time error with state.SystemMenu.Count

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.

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors