Forum Discussion

KLabrie's avatar
KLabrie
Occasional Contributor
9 years ago

Object invoked disconnect from client at website deployment

Hi,

 

I need to run smoke test at the deployment of our website. The test works, except at the deployment. I always get an error native.

 

Error: The object invoked has disconnected from its clients.
at Error (native)

 

This error occurs at every deployment. I rerun the same test right after the failure and it pass.

Might it be something from our website that cause this or a bug in TestComplete?

 

I am using TC12.10.602.7 - Our website is in asp.NET

 

--EDIT--

Here the code I use

 

function getAllPages()
{
var arrPages = Sys.Browser('chrome').FindAllChildren("ObjectType", "Page", 1).toArray();
return arrPages;
}

function getCurrentPage()
{
var objCurrentPage = null;
var arrPages = getAllPages();

var stopTime = GetTickCount() + 30000;

while (objCurrentPage === null && arrPages.length > 0)
{
if (GetTickCount() >= stopTime)
{
Log.Warning("Timeout Reached, unable to get the current page");
break;
}

for (indPage in arrPages)
{
var objPage = arrPages[indPage];

if ( objPage.Enabled && objPage.Visible )
{
objCurrentPage = objPage;
break;
}
}
}

return objCurrentPage;
}

function tryGetElementByCSS(cssSelector)
{
var elemFound = null;
var fromElement = null;

var wait_timeout = 10000;
var max_wait_timeout = GetTickCount() + wait_timeout;
do
{
if ( (wait_timeout > 0) && (GetTickCount() > max_wait_timeout) )
{
var strExtraInfo = "CSS Selector:" + cssSelector;

Log.Warning(" TIMEOUT:'" + wait_timeout + "' milliseconds reached when trying to get element", strExtraInfo);
break;
}

fromElement = getCurrentPage().contentDocument;
elemFound = fromElement.querySelector(cssSelector);
}
while (elemFound == null)

return elemFound;
}

function test()
{
Sys.Browser('chrome').ToUrl('...');
var tableObj = tryGetElementByCSS('div.page section.list');

return (tableObj != null);
}

 With my code, the page should wait at least 30sec before returning false, but i got the error after 6-12 sec of execution.

 

  • I fix my problem,

     

    I was getting a problem cause the time i was getting the document object and the time i was doing a query selector. The page was refreshing (due to the first load) and then my object got disconnected when trying to do the querySelector.

     

    Basicly i did :

     

    try
    {
       fromElement = getCurrentPage().contentDocument;
       elemFound = fromElement.querySelector(cssSelector);
    }
    catch (ex)
    {
        fromElement = null;
        elemFound = null;
    }

    So if the problem occur i just continue my loop and return null if I don't get what i want ater the timeout (for my case, it's doing what i want). 

  • KLabrie's avatar
    KLabrie
    Occasional Contributor

    I fix my problem,

     

    I was getting a problem cause the time i was getting the document object and the time i was doing a query selector. The page was refreshing (due to the first load) and then my object got disconnected when trying to do the querySelector.

     

    Basicly i did :

     

    try
    {
       fromElement = getCurrentPage().contentDocument;
       elemFound = fromElement.querySelector(cssSelector);
    }
    catch (ex)
    {
        fromElement = null;
        elemFound = null;
    }

    So if the problem occur i just continue my loop and return null if I don't get what i want ater the timeout (for my case, it's doing what i want). 

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Can you post the code being executed? The error out of context is unhelpful.

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Here's my thinking... and this is just a guess, mind you.

    Since it is running just fine after the deployment is done, my guess is that there is some code processing happening during the deployment that is causing pages to refresh or objects on those pages to refresh.  So, handles to a particular page might be destroyed or reset during that processing.  Looking at the "getCurrentPage" method, that is my candidate for the problem.

     

    Do you have a particular line of code that is generating that error?  If you double click on the error in the TestComplete log, what line does it take you to?  That might help narrow down the issue a bit more.

    • KLabrie's avatar
      KLabrie
      Occasional Contributor

      When the error occurs, double clicking on the log take me to the closest catch.

       

      And Your idea of the website doing a refresh, that what I think too, but wanted an approval of this idea.

      • tristaanogre's avatar
        tristaanogre
        Esteemed Contributor

        There's no "catch" statement in the code you posted... so, I'm assuming the catch is being picked up somewhere else?

        Might not be a bad idea, for debugging purposes (if not simply to make some "good" code out of it) to add try/catch/finally logic to these routines to see if we can find where the problem is happening.  If you're running JavaScript, you can even, in your catch, write the stack to the log like

         

        try {
        //do stuff
        }
        catch (e) {
            Log.Warning('Something dumb happened: ' +e.message, e.stack);
        }
        finally {
        //clean up on row 12....
        }