Forum Discussion

RUDOLF_BOTHMA's avatar
RUDOLF_BOTHMA
Community Hero
7 years ago

WaitCell and object does not exist

Afternoon folks,

 

I'm running into an intermittent issue I hope have you have ideas about.   There are loads of questions that are ALMOST the same, but none of them seem to be quite what I'm experiencing.   Short summary:  if I use WaitCell, very occasionally the WaitCell call itself causes "The object "Cell(0,0) does not exist" error.  The test will continue running, but because there's an error, the test is marked as failed.

 

the code:

grid.RefreshMappingInfo(); // I can sort the grid, so need to refresh the mapping just in case, else the mappings will be broken
var waitCell = grid.WaitCell(0,0,10000); 
//The object doesn't exist and is output to the error about 0.5 seconds after the call
grid.FindChildEx(… //this works again

I'm using it as a way to confirm that RefreshMappingInfo()has completed before I try and use Find methods again.  At worst it should return a stub, right ?

  • Edit: clarified code.

     

    Well, after extensive testing I can say that the issue is gone.  The changes I made as a result of this thread has both made my scripts faster and more reliable - thanks :smileyvery-happy:  It didn't resolve the majority of the issues though.  I finally found what is causing the majority of the errors and it has nothing to do with this.  The problem lies with this piece of code that posts an image of a parent of the tested object because sometimes just seeing a blank textbox doesn't mean anything:

    WriteAnEntry(Aliases.browser...MyTextBox,"I'm writing to the textbox",3);
    
    function WriteAnEntry(aliasObj,messageText,addPicture,moveXTiersUpforPicture)
    {
    	if(aliasObj===null || aliasObj==undefined || !aliasObj.Exists)
      {
        Log.Message(messageText);
    		return;
      }
    	
    	var imageobject = aliasobject;
    	var currenTier = 0
    	if(addPicture)
    	{
    		while(imageobject!=null && imageobject!=undefined&&currenTier<moveXTiersUpforPicture)
    		{
    			if(imageobject.ObjectType!="Form") //Don't go TOO high'
    				break;
    	
    			currenTier++;	
    			if(imageobject.Parent !=null && imageobject.Parent !=undefined && imageobject.Parent.Exists)
    			{
    					imageobject = imageobject.Parent;			
    			}	
    		}	
    	}
    var testtheobject = imageobject!=null && imageobject!=undefined&& imageobject.Exists;
    //testtheobject is true now //nowhere in the above code do I ever allocate a null/undefined/!exists to my imageobject var //but, very occasionally when I do the following call, the image object is gone, //so it's the testing for null or undefined causes the error Log.Message(messageText,"", pmNormal, "",(addPicture && imageobject!=null && imageobject!=undefined ) ? imageobject:""); }

    So, how did I fix it ?  Try.. Catch

     

    var canDoImage = null;
    		var placeholderObj = null;
    		try
    		{
    				placeholderObj = (imageobj!=null && imageobj!=undefined && imageobj.Exists) ? imageobj : null;
    				if(placeholderObj==null)
    				{
    					canDoImage = false;    
    				}				
    		}
    		catch (e)
    		{				
    				canDoImage = false;    
    		}
       
        Log.Message(messageText,"", pmNormal, "",(canDoImage && placeholderObj!=null ) ? placeholderObj:null);

     I have NO idea how that object gets lost, but there you have it...

     

     

  • https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/web-objects/wait-method-web-object.html

    Result Value

    The method returns web objects of the specified type. If the required object is available before the time elapses, the method returns the object. Otherwise, it returns a stub object. To check if the returned objects exist, use the Existsproperty.

     

    You need to look at Exists so you can capture the failure and go by it

    https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/exists-property.html

     

     

     

    • RUDOLF_BOTHMA's avatar
      RUDOLF_BOTHMA
      Community Hero

      Not entirely sure that's quite it.  It's the actual WaitCell(0,0,1000) which is causing the error.  In the next line of code in my watch list, the object I just got from WaitCell is a cell with a .Exists value of true, so it's not that I'm trying to do something with the returned object later and then it doesn't exist.  It's that the WaitCell call says the object doesn't exist, but then happily returns an object that does exist.  Does that mean each time BEFORE I do I need to get the object with a Find([cellproperties],[cellvalues],1000) to check it exists and only then WaitCell(0,0,1000) again for the same object ?  That would really impact performance if I had to search for things twice each time

      • Marsha_R's avatar
        Marsha_R
        Moderator

        Using WaitCell is correct, but if you're saying that WaitCell fails and then right after that the cell Exists, what happens if you just make WaitCell wait a little longer?  It might be too long sometimes but it would catch the occasional failures.

         

        We had enough of those kind of errors that I actually ended up slowing the whole test run down just a little so it wouldn't just run in 60 secs and fail miserably.

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    > I can sort the grid, so need to refresh the mapping 

    Just a wild guess as I don't know what and how is implemented in your tested application:

    -- Might it be that sorting or some other action makes the grid itself to be recreated within the page DOM? (Possibly, with additional delay to request and populate the grid with data.)

    If the above guess is correct, then the problem may be not with the Cell object, but with grid one. (Because of been accessed via Aliasing/Namemapping the grid object will be cached by TestComplete and not destroyed when the script on the page modifies the DOM.)

    To verify the above idea, try something like this:

    Either

    grid.RefreshMappingInfo();

    grid.WaitProperty('Exists', true, 10000);

    or

    grid = Aliases.<IntermediateObjects>.WaitAliasChild('grid', 10000);

     

    and then

    grid.FindChildEx(…)

     

    Does the above help?

     

     

    • RUDOLF_BOTHMA's avatar
      RUDOLF_BOTHMA
      Community Hero

      Might it be that sorting or some other action makes the grid itself to be recreated within the page DOM? (Possibly, with additional delay to request and populate the grid with data.) 


      Based on all the other errors I was getting with objects being null, disconnecting from invoked etc, I'm convinced it does, which is why I'm always doing the RefreshMappingInfo();

       

      I didn't think a mapping info refresh would cause an object to actually stop existing, but I guess it makes sense.  I'll go with grid.WaitProperty, since my grid isn't a direct child of an aliased object.  Back in a bit :smileyvery-happy:

       

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        Actually... I wonder if it's the grid itself that doesn't exist when calling "WaitCell".  If that's the line that's generating the error, then WaitCell itself is not the problem, it's the grid object that's the problem.

        Where is the line of code that is assigning the value to the "grid" variable?  That's where you need to put "wait" code in... to wait for "grid" to exist first using a FindChild or WaitChild or something similar.